예제 #1
0
        public static PipeValue Map(this PipeValue value, PipeLambda map)
        {
            CommonHelper.ConfirmNotNull(map, "map");
            PipeValuePropertyEnumerator enumerator = value.GetEnumerator();
            PipeValueObjectBuilder      collection = new PipeValueObjectBuilder(value.IsArray);

            while (enumerator.MoveNext())
            {
                collection.Add(map.Invoke(enumerator), enumerator.CurrentKey);
            }
            return(collection);
        }
예제 #2
0
        public static PipeValue First(this PipeValue value, PipeLambda fn, bool returnBoolean = false, bool negate = false)
        {
            CommonHelper.ConfirmNotNull(fn, "fn");
            PipeValuePropertyEnumerator enumerator = value.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (negate ^ (bool)fn.Invoke(enumerator))
                {
                    return(returnBoolean ? true : enumerator.CurrentValue);
                }
            }
            return(returnBoolean ? false : PipeValue.Undefined);
        }
예제 #3
0
        public static PipeValue Where(this PipeValue value, PipeLambda filter)
        {
            CommonHelper.ConfirmNotNull(filter, "filter");
            PipeValuePropertyEnumerator enumerator = value.GetEnumerator();
            PipeValueObjectBuilder      collection = new PipeValueObjectBuilder(value.IsArray);

            while (enumerator.MoveNext())
            {
                if ((bool)filter.Invoke(enumerator))
                {
                    collection.Add(enumerator.CurrentValue, enumerator.CurrentKey);
                }
            }
            return(collection);
        }