@Test public void ap() { FreeAp<DSL_, Integer> freeAp = FreeAp.lift(new ReadInt(123)); FreeAp<DSL_, Function1<? super Integer, ? extends String>> apply = FreeAp.pure(Object::toString); Id<Integer> foldMap = freeAp.ap(apply) .map(String::length) .foldMap(idTransform(), IdInstances.applicative()).fix(toId()); assertEquals(Id.of(3), foldMap); }
public <B> FreeAp<F, B> ap(FreeAp<F, Function1<? super A, ? extends B>> apply) { if (apply instanceof Pure) { Pure<F, Function1<? super A, ? extends B>> pure = (Pure<F, Function1<? super A, ? extends B>>) apply; return map(pure.value); } return apply(this, apply); }
FreeAp implements FreeApOf<F, A> { public <B> FreeAp<F, B> ap(FreeAp<F, Function1<? super A, ? extends B>> apply) { if (apply instanceof Pure) { Pure<F, Function1<? super A, ? extends B>> pure = (Pure<F, Function1<? super A, ? extends B>>) apply; return map(pure.value); } return apply(this, apply); } }
FreeAp implements FreeApOf<F, A> { public <B> FreeAp<F, B> ap(FreeAp<F, Function1<? super A, ? extends B>> apply) { if (apply instanceof Pure) { Pure<F, Function1<? super A, ? extends B>> pure = (Pure<F, Function1<? super A, ? extends B>>) apply; return map(pure.value); } return apply(this, apply); } private  FreeAp(); }
FreeAp implements FreeApOf<F, A> { public <B> FreeAp<F, B> ap(FreeAp<F, Function1<? super A, ? extends B>> apply) { if (apply instanceof Pure) { Pure<F, Function1<? super A, ? extends B>> pure = (Pure<F, Function1<? super A, ? extends B>>) apply; return map(pure.value); } return apply(this, apply); } private  FreeAp(); abstract FreeAp<F, B> map(Function1<? super A, ? extends B> mapper); FreeAp<F, B> ap(FreeAp<F, Function1<? super A, ? extends B>> apply); Kind<F, A> fold(Applicative<F> applicative); FreeAp<G, A> compile(FunctionK<F, G> transformer); FreeAp<G, A> flatCompile(
      FunctionK<F, Kind<FreeAp_, G>> functionK, Applicative<Kind<FreeAp_, G>> applicative); M analyze(FunctionK<F, Kind<Const_, M>> functionK, Applicative<Kind<Const_, M>> applicative); Free<F, A> monad(); @SuppressWarnings({"rawtypes", "unchecked"}) Kind<G, A> foldMap(FunctionK<F, G> functionK, Applicative<G> applicative); static FreeAp<F, T> pure(T value); static FreeAp<F, T> lift(Kind<F, T> value); static FreeAp<F, R> apply(FreeAp<F, ? extends T> value, 
      FreeAp<F, ? extends Function1<? super T, ? extends R>> mapper); static FunctionK<F, Kind<FreeAp_, G>> functionKF(FunctionK<F, G> functionK); @SuppressWarnings("unchecked") static Applicative<Kind<FreeAp_, F>> applicativeF(); }
FreeAp implements FreeApOf<F, A> { public <B> FreeAp<F, B> ap(FreeAp<F, Function1<? super A, ? extends B>> apply) { if (apply instanceof Pure) { Pure<F, Function1<? super A, ? extends B>> pure = (Pure<F, Function1<? super A, ? extends B>>) apply; return map(pure.value); } return apply(this, apply); } private  FreeAp(); abstract FreeAp<F, B> map(Function1<? super A, ? extends B> mapper); FreeAp<F, B> ap(FreeAp<F, Function1<? super A, ? extends B>> apply); Kind<F, A> fold(Applicative<F> applicative); FreeAp<G, A> compile(FunctionK<F, G> transformer); FreeAp<G, A> flatCompile(
      FunctionK<F, Kind<FreeAp_, G>> functionK, Applicative<Kind<FreeAp_, G>> applicative); M analyze(FunctionK<F, Kind<Const_, M>> functionK, Applicative<Kind<Const_, M>> applicative); Free<F, A> monad(); @SuppressWarnings({"rawtypes", "unchecked"}) Kind<G, A> foldMap(FunctionK<F, G> functionK, Applicative<G> applicative); static FreeAp<F, T> pure(T value); static FreeAp<F, T> lift(Kind<F, T> value); static FreeAp<F, R> apply(FreeAp<F, ? extends T> value, 
      FreeAp<F, ? extends Function1<? super T, ? extends R>> mapper); static FunctionK<F, Kind<FreeAp_, G>> functionKF(FunctionK<F, G> functionK); @SuppressWarnings("unchecked") static Applicative<Kind<FreeAp_, F>> applicativeF();  }