Bevisuali.UX.ExtSerialization.ToRandomVariableSpace C# (CSharp) Method

ToRandomVariableSpace() public static method

public static ToRandomVariableSpace ( this json0 ) : Space
json0 this
return Space
        public static Space ToRandomVariableSpace(this JToken json0)
        {
            JObject json = (JObject)json0;
            if (json.Property("discrete") != null)
            {
                float[] values = json.Property("discrete").Value.Values<float>().ToArray();
                string[] labels =
                    Utils.Try(() => json.Property("labels").Value.Values<string>().ToArray(), null);
                var zipped =
                    labels != null
                    ? values.Zip(labels, (v,l) => new Tuple<float, string>(v, l))
                    : values.Select(v => new Tuple<float, string>(v, ""));
                return Space.NewDiscrete(new FSharpMap<float, string>(zipped));
            }
            else
            {
                throw new Exception();
            }
        }