Ejemplo n.º 1
0
        public static OptionAsync <Arr <B> > Traverse <A, B>(this Arr <OptionAsync <A> > ma, Func <A, B> f)
        {
            return(new OptionAsync <Arr <B> >(Go(ma, f)));

            async Task <(bool, Arr <B>)> Go(Arr <OptionAsync <A> > ma, Func <A, B> f)
            {
                var rb = await Task.WhenAll(ma.Map(a => a.Map(f).Data)).ConfigureAwait(false);

                return(rb.Exists(d => !d.IsSome)
                     ? (false, default)
Ejemplo n.º 2
0
        //
        // Collections
        //

        public static TryAsync <Arr <B> > Traverse <A, B>(this Arr <TryAsync <A> > ma, Func <A, B> f)
        {
            return(ToTry(() => Go(ma, f)));

            async Task <Result <Arr <B> > > Go(Arr <TryAsync <A> > ma, Func <A, B> f)
            {
                var rb = await Task.WhenAll(ma.Map(a => a.Map(f).Try())).ConfigureAwait(false);

                return(rb.Exists(d => d.IsFaulted)
                    ? rb.Filter(b => b.IsFaulted).Map(b => new Result <Arr <B> >(b.Exception)).Head()
                    : new Result <Arr <B> >(new Arr <B>(rb.Map(d => d.Value))));
            }
        }
Ejemplo n.º 3
0
        //
        // Collections
        //

        public static TryOptionAsync <Arr <B> > Traverse <A, B>(this Arr <TryOptionAsync <A> > ma, Func <A, B> f)
        {
            return(ToTry(() => Go(ma, f)));

            async Task <OptionalResult <Arr <B> > > Go(Arr <TryOptionAsync <A> > ma, Func <A, B> f)
            {
                var rb = await Task.WhenAll(ma.Map(a => a.Map(f).Try()));

                return(rb.Exists(d => d.IsFaulted) ? rb.Filter(b => b.IsFaulted).Map(b => new OptionalResult <Arr <B> >(b.Exception)).Head()
                     : rb.Exists(d => d.IsNone) ? OptionalResult <Arr <B> > .None
                     : new OptionalResult <Arr <B> >(new Arr <B>(rb.Map(d => d.Value.Value))));
            }
        }
Ejemplo n.º 4
0
        public static EitherAsync <L, Arr <B> > Traverse <L, A, B>(this Arr <EitherAsync <L, A> > ma, Func <A, B> f)
        {
            return(new EitherAsync <L, Arr <B> >(Go(ma, f)));

            async Task <EitherData <L, Arr <B> > > Go(Arr <EitherAsync <L, A> > ma, Func <A, B> f)
            {
                var rb = await Task.WhenAll(ma.Map(a => a.Map(f).Data)).ConfigureAwait(false);

                return(rb.Exists(d => d.State == EitherStatus.IsLeft)
                    ? rb.Filter(d => d.State == EitherStatus.IsLeft).Map(d => EitherData.Left <L, Arr <B> >(d.Left)).Head()
                    : EitherData.Right <L, Arr <B> >(new Arr <B>(rb.Map(d => d.Right))));
            }
        }
Ejemplo n.º 5
0
 public static Que <Arr <B> > Sequence <A, B>(this Arr <A> ta, Func <A, Que <B> > f) =>
 ta.Map(f).Traverse(Prelude.identity);
Ejemplo n.º 6
0
 public static Reader <Env, Arr <B> > Sequence <Env, A, B>(this Arr <A> ta, Func <A, Reader <Env, B> > f) =>
 ta.Map(f).Sequence();
Ejemplo n.º 7
0
 public static Eff <RT, Arr <B> > Sequence <RT, A, B>(this Arr <A> ta, Func <A, Eff <RT, B> > f) where RT : struct =>
 ta.Map(f).Sequence();
Ejemplo n.º 8
0
 public static HashSet <Arr <B> > Traverse <A, B>(this Arr <HashSet <A> > ma, Func <A, B> f) =>
 toHashSet(CollT.AllCombinationsOf(ma.Map(xs => xs.ToList()).ToArray(), f)
           .Map(toArray));
Ejemplo n.º 9
0
 public static Try <Arr <B> > Sequence <A, B>(this Arr <A> ta, Func <A, Try <B> > f) =>
 ta.Map(f).Sequence();
Ejemplo n.º 10
0
 public static Aff <Arr <B> > SequenceSerial <A, B>(this Arr <A> ta, Func <A, Aff <B> > f) =>
 ta.Map(f).SequenceSerial();
Ejemplo n.º 11
0
 public static Aff <Arr <B> > SequenceParallel <A, B>(this Arr <A> ta, Func <A, Aff <B> > f) =>
 ta.Map(f).SequenceParallel();
Ejemplo n.º 12
0
 public static Validation <MonoidFail, Fail, Arr <B> > Sequence <MonoidFail, Fail, A, B>(this Arr <A> ta, Func <A, Validation <MonoidFail, Fail, B> > f)
     where MonoidFail : struct, Monoid <Fail>, Eq <Fail> =>
 ta.Map(f).Traverse(Prelude.identity);
Ejemplo n.º 13
0
 public static ValueTask <Arr <B> > Sequence <A, B>(this Arr <A> ta, Func <A, ValueTask <B> > f) =>
 ta.Map(f).Sequence();
Ejemplo n.º 14
0
 public static RWS <MonoidW, Env, W, S, Arr <B> > Sequence <MonoidW, Env, W, S, A, B>(this Arr <A> ta, Func <A, RWS <MonoidW, Env, W, S, B> > f)
     where MonoidW : struct, Monoid <W> =>
 ta.Map(f).Sequence();
Ejemplo n.º 15
0
 public static State <S, Arr <B> > Sequence <S, A, B>(this Arr <A> ta, Func <A, State <S, B> > f) =>
 ta.Map(f).Sequence();
Ejemplo n.º 16
0
        public static async ValueTask <Arr <B> > Traverse <A, B>(this Arr <ValueTask <A> > ma, Func <A, B> f)
        {
            var rb = await Task.WhenAll(ma.Map(async a => f(await a.ConfigureAwait(false)))).ConfigureAwait(false);

            return(new Arr <B>(rb));
        }
Ejemplo n.º 17
0
 public static Aff <RT, Arr <B> > SequenceSerial <RT, A, B>(this Arr <A> ta, Func <A, Aff <RT, B> > f)
     where RT : struct, HasCancel <RT> =>
 ta.Map(f).SequenceSerial();
Ejemplo n.º 18
0
 public static Aff <RT, Arr <B> > SequenceParallel <RT, A, B>(this Arr <A> ta, Func <A, Aff <RT, B> > f, int windowSize)
     where RT : struct, HasCancel <RT> =>
 ta.Map(f).SequenceParallel(windowSize);
Ejemplo n.º 19
0
 public static Stck <Arr <B> > Traverse <A, B>(this Arr <Stck <A> > ma, Func <A, B> f) =>
 toStack(CollT.AllCombinationsOf(ma.Map(xs => xs.ToList()).ToArray(), f)
         .Map(toArray));
Ejemplo n.º 20
0
 public static HashSet <Arr <B> > Sequence <A, B>(this Arr <A> ta, Func <A, HashSet <B> > f) =>
 ta.Map(f).Sequence();
Ejemplo n.º 21
0
 public static Aff <Arr <B> > SequenceParallel <A, B>(this Arr <A> ta, Func <A, Aff <B> > f, int windowSize) =>
 ta.Map(f).SequenceParallel(windowSize);
Ejemplo n.º 22
0
 public static IEnumerable <Arr <B> > Sequence <A, B>(this Arr <A> ma, Func <A, IEnumerable <B> > f) =>
 ma.Map(f).Sequence();
Ejemplo n.º 23
0
 public static EitherAsync <L, Arr <B> > Sequence <L, A, B>(this Arr <A> ta, Func <A, EitherAsync <L, B> > f) =>
 ta.Map(f).Sequence();
Ejemplo n.º 24
0
 public static Arr <Arr <B> > Traverse <A, B>(this Arr <Arr <A> > xxs, Func <A, B> f) =>
 CollT.AllCombinationsOf(xxs.Map(xs => xs.ToList()).ToArray(), f)
 .Map(toArray)
 .ToArr();
Ejemplo n.º 25
0
 public static Validation <Fail, Arr <B> > Sequence <Fail, A, B>(this Arr <A> ta, Func <A, Validation <Fail, B> > f) =>
 ta.Map(f).Sequence();
Ejemplo n.º 26
0
 public static IEnumerable <Arr <B> > Traverse <A, B>(this Arr <IEnumerable <A> > ma, Func <A, B> f) =>
 CollT.AllCombinationsOf(ma.Map(xs => xs.ToList()).ToArray(), f)
 .Map(toArray);
Ejemplo n.º 27
0
 public static Lst <Arr <B> > Traverse <A, B>(this Arr <Lst <A> > ma, Func <A, B> f) =>
 CollT.AllCombinationsOf(ma.Map(xs => xs.ToList()).ToArray(), f)
 .Map(toArray)
 .Freeze();
Ejemplo n.º 28
0
 public static Writer <MonoidW, W, Arr <B> > Sequence <MonoidW, W, A, B>(this Arr <A> ta, Func <A, Writer <MonoidW, W, B> > f)
     where MonoidW : struct, Monoid <W> =>
 ta.Map(f).Sequence();
Ejemplo n.º 29
0
 public static Option <Arr <B> > Sequence <A, B>(this Arr <A> ta, Func <A, Option <B> > f) =>
 ta.Map(f).Sequence();
Ejemplo n.º 30
0
        //
        // Collections
        //

        public static async Task <Arr <B> > Traverse <A, B>(this Arr <Task <A> > ma, Func <A, B> f)
        {
            var rb = await Task.WhenAll(ma.Map(async a => f(await a)));

            return(new Arr <B>(rb));
        }