Exemplo n.º 1
0
 public static IPromise <ISet <T> > ToSet <T>(IPromiseEnumerator <T> items, IEqualityComparer <T> comparer)
 {
     return(ReduceAlgorithm.Reduce(items, (prev, current) =>
     {
         prev.Add(current);
         return prev;
     }, (ISet <T>)(new HashSet <T>(comparer))));
 }
Exemplo n.º 2
0
 public static IPromise <List <T> > ToList <T>(IPromiseEnumerator <T> items)
 {
     return(ReduceAlgorithm.Reduce(items, (prev, current) =>
     {
         prev.Add(current);
         return prev;
     }, new List <T>()));
 }
Exemplo n.º 3
0
        public static IPromise <long> LongCount <T>(IPromiseEnumerator <T> items, Func <T, int, IPromise <bool> > filter)
        {
            return(ReduceAlgorithm.Reduce <T, long>(items, (prev, current, index) =>
            {
                return filter(current, index).Then(pick =>
                {
                    if (pick)
                    {
                        return prev + 1;
                    }

                    return prev;
                });
            }, 0));
        }
Exemplo n.º 4
0
 public static IPromise <T> LastOrDefault <T>(IPromiseEnumerator <T> items, T defaultValue)
 {
     return(ReduceAlgorithm.Reduce(items, (prev, current) => current, defaultValue));
 }
Exemplo n.º 5
0
 public static IPromise <IPromiseEnumerator <T> > Each <T>(IPromiseEnumerator <T> items, Func <T, int, IPromise> action)
 {
     return(ReduceAlgorithm.Reduce(items, (prev, current, index) => action(current, index).Immediately.Then(() => items), items));
 }