Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
 public override int Compare(PipeValue x, PipeValue y)
 {
     if (x.IsArray && y.IsArray)
     {
         int result = 0;
         PipeValuePropertyEnumerator iterX = x.GetEnumerator();
         PipeValuePropertyEnumerator iterY = y.GetEnumerator();
         while (iterX.MoveNext() && iterY.MoveNext() && result == 0)
         {
             result = Compare(iterX.CurrentValue, iterY.CurrentValue);
         }
         return(result != 0 ? result : iterX.Count - iterY.Count);
     }
     return(x == y ? 0 : !x.IsEvallable || x < y ? -1 : !y.IsEvallable || x > y ? 1 : 0);
 }
Exemplo n.º 4
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);
        }