public override IApplicative <TLeft, TB> Apply <TA, TB>(IApplicative <TLeft, Func <TA, TB> > ff, IApplicative <TLeft, TA> fa) { var mf = (Either <TLeft, Func <TA, TB> >)ff; var ma = (Either <TLeft, TA>)fa; return(mf.Ap(ma)); }
public override IApplicative <TB> Apply <TA, TB>(IApplicative <Func <TA, TB> > ff, IApplicative <TA> fa) { var mf = (Maybe <Func <TA, TB> >)ff; var ma = (Maybe <TA>)fa; return(mf.Ap(ma)); }
/// <summary> /// The asynchronous version of <see cref="IApplicative{TSource}.Ap{TResult}(IApplicative{Func{TSource, TResult}})"/>. /// </summary> /// <typeparam name="TSource">The type of the source.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="x">The task which returns the source-applicative.</param> /// <param name="f">The function to apply to the applicative.</param> public static async Task <IAsyncApplicative <TResult> > ApAsync <TSource, TResult>( this Task <IAsyncApplicative <TSource> > x, IApplicative <Func <TSource, Task <TResult> > > f) { var m = await x; return(await m.ApAsync(f)); }
/// <summary> /// The asynchronous version of <see cref="IApplicative{TSource}.Ap{TResult}(IApplicative{Func{TSource, TResult}})"/>. /// </summary> /// <typeparam name="TSource">The type of the source.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="x">The task which returns the source-applicative.</param> /// <param name="f">The function to apply to the applicative.</param> /// <param name="token">The cancellation token.</param> public static async Task <IAsyncApplicative <TResult> > ApAsync <TSource, TResult>( this Task <IAsyncApplicative <TSource> > x, IApplicative <Func <TSource, Task <TResult> > > f, CancellationToken token) { var m = await x; return(await m.ApAsync(f, token)); }
/// <inheritdoc /> public async Task <IAsyncApplicative <TResult> > ApAsync <TResult>(IApplicative <Func <T, Task <TResult> > > f) { if (f == null || !(f is Identity <Func <T, Task <TResult> > > fIdentity)) { throw new InvalidCastException(); } return(new Identity <TResult>(await fIdentity.Value(Value))); }
/// <inheritdoc /> public IApplicative <TResult> Ap <TResult>(IApplicative <Func <T, TResult> > f) { if (f == null || !(f is Identity <Func <T, TResult> > fIdentity)) { throw new InvalidCastException(); } return(new Identity <TResult>(fIdentity.Value(Value))); }
/// <inheritdoc /> public IApplicative <TResult> Ap <TResult>(IApplicative <Func <T, TResult> > f) { if (!(f is Io <Func <T, TResult> > fIo)) { throw new InvalidCastException(); } var valueThis = value; return(new Io <TResult>(async() => (await fIo.Run())(await valueThis()))); }
/// <inheritdoc /> public IApplicative <TResult> Ap <TResult>(IApplicative <Func <T, TResult> > f) { if (f == null || f is not IEnumerable <Func <T, TResult> > functions) { throw new InvalidCastException(); } var ys = SetCoalesce(); return(new FuncSet <TResult>(functions.SelectMany(fx => ys.Select(y => fx(y))))); }
/// <inheritdoc /> public IApplicative <TResult> Ap <TResult>(IApplicative <Func <T, TResult> > f) { if (f == null || !(f is IEnumerable <Func <T, TResult> >)) { throw new InvalidCastException(); } var functions = (IEnumerable <Func <T, TResult> >)f; var ys = LocalView(); return(new Lst <TResult>(functions.SelectMany(fx => Enumerable.Select(ys, y => fx(y))))); }
/// <inheritdoc /> public IApplicative <TResult> Ap <TResult>(IApplicative <Func <TValue, TResult> > f) { if (f == null || !(f is Reader <TEnvironment, Func <TValue, TResult> >)) { throw new InvalidCastException(); } var fState = f as Reader <TEnvironment, Func <TValue, TResult> >; return(new Reader <TEnvironment, TResult>(s => { var func = fState.Run(s); var arg = runReader(s); return func(arg); })); }
public ApplicativeLawsTests(IApplicative <TF> applicative, IEqK <TF> eqK) : base(applicative, eqK) { var applicativeLaws = new ApplicativeLaws <TF>(applicative); Add("Applicative Identity", args => applicativeLaws.ApplicativeIdentity(args.LiftedA).Holds(eqK)); Add("Applicative Homomorphism", args => applicativeLaws.ApplicativeHomomorphism(args.A, args.FuncAtoB).Holds(eqK)); Add("Applicative Interchange", args => applicativeLaws.ApplicativeInterchange(args.A, args.LiftedFuncAtoB).Holds(eqK)); Add("Applicative Map", args => applicativeLaws.ApplicativeMap(args.LiftedA, args.FuncAtoB).Holds(eqK)); Add("Ap Product Consistent", args => applicativeLaws.ApProductConsistent(args.LiftedA, args.LiftedFuncAtoB).Holds(eqK)); }
/// <inheritdoc /> public IApplicative <TResult> Ap <TResult>(IApplicative <Func <T8, TResult> > f) { if (f is null || !(f is Either <T1, T2, T3, T4, T5, T6, T8, Func <T8, TResult> > that)) { throw new InvalidCastException(); } if (IsEigth && that.IsEigth) { return(new Either <T1, T2, T3, T4, T5, T6, T7, TResult>(new Either8 <TResult>(((Func <T8, TResult>)that.Value)((T8)Value)))); } else if (!IsEigth) { return(CopyError <TResult>()); } else { return(that.CopyError <TResult>()); } }
Func <IApplicative <A>, IApplicative <B> > IApplicative <A> .ApS <B>(IApplicative <Func <A, B> > appl) { return(ia => ApS((Cont <R, Func <A, B> >)appl)((Cont <R, A>)ia)); }
public static Func <IApplicative <T>, None> Ap <T>(IApplicative <Func <T, None> > i) { return(a => Instance); }
/// <summary> /// Constructs a <see cref="IAlternative"/> predicated on supplied data /// </summary> /// <param name="applicative">A realization of the <see cref="IApplicative"/> typeclass </param> /// <typeparam name="X">The function domain</typeparam> /// <typeparam name="CX">A domain container</typeparam> /// <typeparam name="CFX">A function container</typeparam> /// <typeparam name="CY">A codomain container</typeparam> /// <typeparam name="Y">The function codomain</typeparam> public static IAlternative <X, CX, CFX, Y, CY> make <X, CX, CFX, Y, CY>(IApplicative <X, CX, CFX, Y, CY> applicative, CX zero) where CX : IContainer <X> where CFX : IContainer <Func <X, Y> > where CY : IContainer <Y> => new Alternative <X, CX, CFX, Y, CY>(applicative, zero);
Func <IApplicative <T>, IApplicative <U> > IApplicative <T> .ApS <U>(IApplicative <Func <T, U> > appl) { return(t => ApS((IO <Func <T, U> >)appl)((IO <T>)t)); }
public Alternative(IApplicative <X, CX, CFX, Y, CY> applicative, CX empty) { this._applicative = applicative; this.empty = empty; }
public abstract IApplicative <TB> Apply <TA, TB>(IApplicative <Func <TA, TB> > ff, IApplicative <TA> fa);
IApplicative <TReturn> IApplicative <TRight> .Apply <TReturn>(IApplicative <Func <TRight, TReturn> > f) { return(this.Apply <TReturn>((Either <TLeft, Func <TRight, TReturn> >)f)); }
Func <IApplicative <T>, IApplicative <U> > IApplicative <T> .ApS <U>(IApplicative <Func <T, U> > appl) { return(t => ApS((Writer <Func <T, U>, W>)appl)((Writer <T, W>)t)); }
IApplicative <TReturn> IApplicative <T> .ApplyRight <TReturn>(IApplicative <TReturn> other) { return(this.ApplyRight <TReturn>((NonEmptyList <TReturn>)other)); }
IApplicative <TReturn> IApplicative <T> .Apply <TReturn>(IApplicative <Func <T, TReturn> > f) { return(this.Apply <TReturn>((NonEmptyList <Func <T, TReturn> >)f)); }
IApplicative <U> IApplicative <T> .Ap <U>(IApplicative <Func <T, U> > appl) { return(Ap <U>((IO <Func <T, U> >)appl)); }
Func <IApplicative <V>, IApplicative <U> > IApplicative <V> .ApS <U>(IApplicative <Func <V, U> > appl) { return(v => ApS((State <S, Func <V, U> >)appl)((State <S, V>)v)); }
IApplicative <U> IApplicative <V> .Ap <U>(IApplicative <Func <V, U> > appl) { return(Ap((State <S, Func <V, U> >)appl)); }
public IApplicative <B> Apply <B>(IApplicative <Func <A, B> > f) => ((IMonad <Func <A, B> >)f).Bind(f => this.Bind(x => Return(f(x))));
IApplicative <U> IApplicative <T> .Ap <U>(IApplicative <Func <T, U> > appl) { return(Ap <U>((Writer <Func <T, U>, W>)appl)); }
IApplicative <B> IApplicative <A> .Ap <B>(IApplicative <Func <A, B> > appl) { return(Ap((Cont <R, Func <A, B> >)appl)); }
IApplicative <TReturn> IApplicative <TRight> .ApplyRight <TReturn>(IApplicative <TReturn> other) { return(this.ApplyRight <TReturn>((Either <TLeft, TReturn>)other)); }
public static IApplicative <B> Apply <A, B>(this IApplicative <Func <A, B> > f, IApplicative <A> a) => a.Apply(f);