/** * Promotes this function to map over a product-1. * * @return This function promoted to map over a product-1. */ public static <A, B> F<P1<A>, P1<B>> mapP1(final F<A, B> f) { return p -> p.map(f); }
/** * Promote any function to a transformation between P1s. * * @param f A function to promote to a transformation between P1s. * @return A function promoted to operate on P1s. */ public static <A, B> F<P1<A>, P1<B>> map_(final F<A, B> f) { return a -> a.map(f); }
/** * Maps a concurrent function over a Product-1 inside a Promise. * * @param a A product-1 across which to map. * @param f A concurrent function to map over the product inside a promise. * @return A promised product of the result of mapping the given function over the given product. */ public <A, B> Promise<P1<B>> mapM(final P1<A> a, final F<A, Promise<B>> f) { return sequence(a.map(f)); }
/** * Maps the given function across this vector. * * @param f The function to map across this vector. * @return A new vector after the given function has been applied to each element. */ public <B> V6<B> map(final F<A, B> f) { return new V6<>(head.map(f), tail.map(f)); }
/** * Maps the given function across this vector. * * @param f The function to map across this vector. * @return A new vector after the given function has been applied to each element. */ public <B> V7<B> map(final F<A, B> f) { return new V7<>(head.map(f), tail.map(f)); }
/** * Maps the given function across this vector. * * @param f The function to map across this vector. * @return A new vector after the given function has been applied to each element. */ public <B> V5<B> map(final F<A, B> f) { return new V5<>(head.map(f), tail.map(f)); }
/** * Maps the given function across this vector. * * @param f The function to map across this vector. * @return A new vector after the given function has been applied to each element. */ public <B> V4<B> map(final F<A, B> f) { return new V4<>(head.map(f), tail.map(f)); }
/** modify polymorphically the target of a {@link PIso} with an Applicative function */ public final F<S, P1<T>> modifyP1F(final F<A, P1<B>> f) { return s -> f.f(get(s)).map(this::reverseGet); }
/** * Maps the given function across this vector. * * @param f The function to map across this vector. * @return A new vector after the given function has been applied to each element. */ public <B> V3<B> map(final F<A, B> f) { return new V3<>(head().map(f), tail().map(f)); }
@Override public F<S, P1<S>> modifyP1F(final F<A, P1<A>> f) { return s -> getOption.f(s).<P1<S>> option( P.p(s), t -> f.f(t).map(b -> set.f(b).f(s)) ); }
@Override public F<S, P1<T>> modifyP1F(final F<A, P1<B>> f) { return s -> f.f(get2.f(s)).apply(f.f(get1.f(s)).<F<B, T>> map(b1 -> b2 -> set.f(b1, b2, s))); }
public final <B> P1<List<B>> traverseP1(final F<A, P1<B>> f){ return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), p(List.nil()) ); }
@Override public F<S, P1<T>> modifyP1F(final F<A, P1<B>> f) { return s -> getOrModify.f(s).either( P.p1(), t -> f.f(t).map(b -> set.f(b).f(s)) ); }
/** * Builds a tree from a seed value. * * @param f A function with which to build the tree. * @return A function which, given a seed value, yields a tree. */ public static <A, B> F<B, Tree<A>> unfoldTree(final F<B, P2<A, P1<Stream<B>>>> f) { return b -> { final P2<A, P1<Stream<B>>> p = f.f(b); return node(p._1(), p._2().map(Stream.<B, Tree<A>>map_().f(unfoldTree(f)))); }; }
public final <C> P1<Validation<E, C>> traverseP1(F<T, P1<C>> f){ return isSuccess() ? f.f(success()).map(Validation::success) : p(fail(e.left().value())); }
/** * Maps the given function over this tree. * * @param f The function to map over this tree. * @return The new Tree after the function has been applied to each element in this Tree. */ public <B> Tree<B> fmap(final F<A, B> f) { return node(f.f(root()), subForest().map(Stream.<Tree<A>, Tree<B>>map_().f(Tree.<A, B>fmap_().f(f)))); }
public <C> P1<Either<A, C>> traverseP1(final F<B, P1<C>> f) { return e.isRight() ? f.f(value()).map(right_()) : p(left(e.left().value())); }
public Stream<A> f(final Tree<A> t, final P1<Stream<A>> xs) { return cons(t.root(), t.subForest().map(Stream.<Tree<A>, Stream<A>>foldRight().f(F2Functions.curry(this)).f(xs._1()))); } };
private Promise<Stream<A>> qs(final Ord<A> o, final Strategy<Unit> s) { if (isEmpty()) return promise(s, p(this)); else { final F<Boolean, Boolean> id = identity(); final A x = head(); final P1<Stream<A>> xs = tail(); final Promise<Stream<A>> left = Promise.join(s, xs.map(flt(o, s, x, id))); final Promise<Stream<A>> right = xs.map(flt(o, s, x, not))._1(); final Monoid<Stream<A>> m = Monoid.streamMonoid(); return right.fmap(m.sum(single(x))).apply(left.fmap(m.sum())); } }