/** * Concatenate (join) a non empty list of non empty lists. * * @param o The non empty list of non empty lists to join. * @return A new non empty list that is the concatenation of the given lists. */ public static <A> NonEmptyList<A> join(final NonEmptyList<NonEmptyList<A>> o) { return o.bind(identity()); }
/** * Joins the given optional value of optional value using a bind operation. * * @param o The optional value of optional value to join. * @return A new optional value that is the join of the given optional value. */ public static <A> Option<A> join(final Option<Option<A>> o) { final F<Option<A>, Option<A>> id = identity(); return o.bind(id); }
/** * Joins two arguments of a function of arity-2 into one argument, yielding a function of arity-1. * * @param f A function whose arguments to join. * @return A function of arity-1 whose argument is substituted for both parameters of <em>f</em>. */ public static <A, B> F<B, A> join(final F<B, F<B, A>> f) { return bind(f, Function.identity()); }
/** * Maps the given transformation across this strategy's codomain (Invariant Functor pattern). * * @param f A transformation from the resulting strategy's domain to this strategy's domain. * @return A new strategy that applies the given transformation before each application of this strategy. */ public Strategy<A> contramap(final F<P1<A>, P1<A>> f) { return xmap(Function.identity(), f); }
/** * Joins the given array of arrays using a bind operation. * * @param o The array of arrays to join. * @return A new array that is the join of the given arrays. */ public static <A> Array<A> join(final Array<Array<A>> o) { final F<Array<A>, Array<A>> id = identity(); return o.bind(id); }
/** * Joins a P1 of a P1 with a bind operation. * * @param a The P1 of a P1 to join. * @return A new P1 that is the join of the given P1. */ public static <A> P1<A> join(final P1<P1<A>> a) { return a.bind(Function.identity()); }
/** * Removes one layer of monadic structure. * * @param a A database action that results in another. * @return A new database action equivalent to the result of the given action. */ public static <A> DB<A> join(final DB<DB<A>> a) { return a.bind(Function.identity()); } }
/** * Maps the given transformation across this strategy's domain (Invariant Functor pattern). * * @param f A transformation from this strategy's codomain to the resulting strategy's codomain. * @return A new strategy that applies the given transformation after each application of this strategy. */ public Strategy<A> map(final F<P1<A>, P1<A>> f) { return xmap(f, Function.identity()); }
/** * Duplicates this promise to a promise of itself (Comonad pattern). * * @return a promise of this promise. */ public Promise<Promise<A>> cojoin() { final F<Promise<A>, Promise<A>> id = identity(); return cobind(id); }
/** * Provides a strategy that performs no evaluation of its argument. * * @return A strategy that performs no evaluation of its argument. */ public static <A> Strategy<A> idStrategy() { return strategy(Function.identity()); }
/** * Joins an either through left. * * @param e The either of either to join. * @return An either after joining. */ public static <A, B> Either<A, B> joinLeft(final Either<Either<A, B>, B> e) { return e.left().bind(identity()); }
/** * Join a set of sets into a single set. * * @param s A set of sets. * @param o An order for the elements of the new set. * @return A new set which is the join of the given set of sets. */ public static <A> Set<A> join(final Ord<A> o, final Set<Set<A>> s) { final F<Set<A>, Set<A>> id = identity(); return s.foldMap(id, Monoid.setMonoid(o)); }
/** * Returns the element at the given index. This is an O(log(n)) operation. * * @param i The index of the element to return. * @return The element at the given index, or throws an error if the index is out of bounds. */ public A index(final int i) { checkBounds(i); return ftree.lookup(Function.identity(), i)._2(); }
/** * Zips two iterables together with a given function, in parallel. * * @param as An iterable to zip with another in parallel. * @param bs An iterable to zip with another in parallel. * @param f A function with which to zip two iterables in parallel. * @return A Promise of a new iterable with the results of applying the given function across the two iterables, stepwise. */ public <A, B, C> Promise<Iterable<C>> parZipWith(final Iterable<A> as, final Iterable<B> bs, final F<A, F<B, C>> f) { return parZipWith(iterableStream(as), iterableStream(bs), f).fmap( Function.vary(Function.<Iterable<C>>identity())); }
/** * The catamorphism for Iterables, implemented as a right fold. * * @param f The function with which to fold the wrapped iterable. * @param z The base case value of the destination type, applied last (rightmost) to the fold. * @return The result of the catamorphism. */ public <B> B foldRight(final F2<A, B, B> f, final B z) { final F<B, B> id = identity(); return foldLeft(curry((k, a, b) -> k.f(f.f(a, b))), id).f(z); }
@Override public F<S, T> modify(final F<A, B> f) { return s -> getOrModify.f(s).either(Function.identity(), a -> set.f(f.f(a)).f(s)); } };
/** * Binds an Iterable-valued function across an Iterable in parallel, concatenating the results into a new Iterable. * * @param as A Iterable to bind across in parallel. * @param f A function to bind across the given Iterable in parallel. * @return A promise of a new Iterable with the given function bound across its elements. */ public <A, B> Promise<Iterable<B>> parFlatMap(final Iterable<A> as, final F<A, Iterable<B>> f) { return parMap(as, f).fmap(IterableW.join()) .fmap(Function.vary(Function.<Iterable<B>>identity())); }
@Override public Either<T, C> getOrModify(final S s) { return PPrism.this.getOrModify(s).right() .bind(a -> other.getOrModify(a).bimap(b -> PPrism.this.set(b).f(s), Function.identity())); }
@Override public Either<T, C> getOrModify(final S s) { return self.getOrModify(s).right() .bind(a -> other.getOrModify(a).bimap(b -> POptional.this.set(b).f(s), Function.identity())); }