Package fj

Interface F<A,​B>

  • All Superinterfaces:
    java.util.function.Function<A,​B>
    All Known Implementing Classes:
    IOFunctions.CharChunkReader, IOFunctions.CharChunkReader2, IOFunctions.LineReader
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface F<A,​B>
    extends java.util.function.Function<A,​B>
    A transformation or function from A to B.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default <C> F<F<B,​C>,​F<A,​C>> andThen()
      First-class composition flipped.
      default <C> F<A,​C> andThen​(F<B,​C> g)
      Function composition flipped.
      default <C> F<F<A,​F<B,​C>>,​F<A,​C>> apply()
      First-class function application in an environment.
      default B apply​(A a)  
      default <C> F<A,​C> apply​(F<A,​F<B,​C>> g)
      Function application in an environment (Applicative Functor).
      default F<A,​Array<B>> arrayK()
      Promotes this function so that it returns its result in a Array.
      default <C> F<F<B,​F<A,​C>>,​F<A,​C>> bind()
      First-class function binding.
      default <C> F<A,​C> bind​(F<B,​F<A,​C>> g)
      Binds a given function across this function (Reader Monad).
      default <C> F<C,​B> contramap​(F<C,​A> f)  
      default F<Actor<B>,​Actor<A>> contramapActor()
      Returns a function that contramaps over a given actor.
      default F<Equal<B>,​Equal<A>> contramapEqual()
      Promotes this function to map over an Equal as a contravariant functor.
      default F<Hash<B>,​Hash<A>> contramapHash()
      Promotes this function to map over a Hash as a contravariant functor.
      default F<Show<B>,​Show<A>> contramapShow()
      Promotes this function to map over a Show as a contravariant functor.
      default <C,​D>
      F<C,​D>
      dimap​(F<C,​A> f, F<B,​D> g)
      Both map (with g) and contramap (with f) the target function.
      default <C> F<A,​Either<B,​C>> eitherLeftK()
      Promotes this function so that it returns its result on the left side of an Either.
      default <C> F<A,​Either<C,​B>> eitherRightK()
      Promotes this function so that it returns its result on the right side of an Either.
      B f​(A a)
      Transform A to B.
      default <C> F<A,​Validation<B,​C>> failK()
      Promotes this function so that it returns its result on the failure side of a Validation.
      default F<Tree<A>,​B> foldMapTree​(Monoid<B> m)
      Returns a function that maps this function over a tree and folds it with the given monoid.
      default F<A,​IterableW<B>> iterableK()
      Promotes this function to return its value in an Iterable.
      default F<A,​P1<B>> lazy()
      Promotes this function so that it returns its result in a product-1.
      default F<A,​List<B>> listK()
      Promotes this function so that it returns its result in a List.
      default <C> F<A,​C> map​(F<B,​C> f)  
      default F<Array<A>,​Array<B>> mapArray()
      Promotes this function to map over a Array.
      default F<P2<A,​A>,​P2<B,​B>> mapBoth()
      Promotes this function to map over both elements of a pair.
      default <X> F<Validation<A,​X>,​Validation<B,​X>> mapFail()
      Promotes this function to map over the failure side of a Validation.
      default <C> F<P2<A,​C>,​P2<B,​C>> mapFst()
      Promotes this function to map over the first element of a pair.
      default F<java.lang.Iterable<A>,​IterableW<B>> mapIterable()
      Promotes this function to map over Iterables.
      default java.util.ArrayList<B> mapJ​(java.util.ArrayList<A> as)
      Maps this function over an ArrayList.
      default java.util.concurrent.ArrayBlockingQueue<B> mapJ​(java.util.concurrent.ArrayBlockingQueue<A> as)
      Maps this function over an ArrayBlockingQueue.
      default java.util.concurrent.ConcurrentLinkedQueue<B> mapJ​(java.util.concurrent.ConcurrentLinkedQueue<A> as)
      Maps this function over a ConcurrentLinkedQueue.
      default java.util.concurrent.CopyOnWriteArrayList<B> mapJ​(java.util.concurrent.CopyOnWriteArrayList<A> as)
      Maps this function over a CopyOnWriteArrayList.
      default java.util.concurrent.CopyOnWriteArraySet<B> mapJ​(java.util.concurrent.CopyOnWriteArraySet<A> as)
      Maps this function over a CopyOnWriteArraySet.
      default java.util.concurrent.LinkedBlockingQueue<B> mapJ​(java.util.concurrent.LinkedBlockingQueue<A> as)
      Maps this function over a LinkedBlockingQueue.
      default java.util.concurrent.PriorityBlockingQueue<B> mapJ​(java.util.concurrent.PriorityBlockingQueue<A> as)
      Maps this function over a PriorityBlockingQueue.
      default java.util.concurrent.SynchronousQueue<B> mapJ​(java.util.concurrent.SynchronousQueue<A> as)
      Maps this function over a SynchronousQueue.
      default java.util.LinkedList<B> mapJ​(java.util.LinkedList<A> as)
      Maps this function over a LinkedList.
      default java.util.PriorityQueue<B> mapJ​(java.util.PriorityQueue<A> as)
      Maps this function over a PriorityQueue.
      default java.util.TreeSet<B> mapJ​(java.util.TreeSet<A> as)
      Maps this function over a TreeSet.
      default <X> F<Either<A,​X>,​Either<B,​X>> mapLeft()
      Promotes this function to map over the left side of an Either.
      default F<List<A>,​List<B>> mapList()
      Promotes this function to map over a List.
      default F<NonEmptyList<A>,​NonEmptyList<B>> mapNel()
      Promotes this function to map over a NonEmptyList.
      default F<Option<A>,​Option<B>> mapOption()
      Promotes this function to map over an optional value.
      default F<P1<A>,​P1<B>> mapP1()
      Promotes this function to map over a product-1.
      default F<Promise<A>,​Promise<B>> mapPromise()
      Promotes this function to map over a Promise.
      default <X> F<Either<X,​A>,​Either<X,​B>> mapRight()
      Promotes this function to map over the right side of an Either.
      default F<Set<A>,​Set<B>> mapSet​(Ord<B> o)
      Promotes this function to map over a Set.
      default <C> F<P2<C,​A>,​P2<C,​B>> mapSnd()
      Promotes this function to map over the second element of a pair.
      default F<Stream<A>,​Stream<B>> mapStream()
      Promotes this function to map over a Stream.
      default <X> F<Validation<X,​A>,​Validation<X,​B>> mapSuccess()
      Promotes this function to map over the success side of a Validation.
      default F<Tree<A>,​Tree<B>> mapTree()
      Promotes this function to map over a Tree.
      default F<TreeZipper<A>,​TreeZipper<B>> mapTreeZipper()
      Promotes this function to map over a TreeZipper.
      default F<Zipper<A>,​Zipper<B>> mapZipper()
      Promotes this function to map over a Zipper.
      default F<A,​NonEmptyList<B>> nelK()
      Promotes this function to return its value in a NonEmptyList.
      default <C> F<F<C,​A>,​F<C,​B>> o()
      First-class function composition
      default <C> F<C,​B> o​(F<C,​A> g)
      Function composition
      default <C> F<F<B,​F<B,​C>>,​F<A,​F<A,​C>>> on()
      Applies this function over the arguments of another function.
      default <C> F<A,​F<A,​C>> on​(F<B,​F<B,​C>> g)
      Applies this function over the arguments of another function.
      default F<Validation<B,​A>,​B> onFail()
      Returns a function that returns the failure side of a given Validation, or this function applied to the success side.
      default F<Either<B,​A>,​B> onLeft()
      Returns a function that returns the left side of a given Either, or this function applied to the right side.
      default F<Either<A,​B>,​B> onRight()
      Returns a function that returns the right side of a given Either, or this function applied to the left side.
      default F<Validation<A,​B>,​B> onSuccess()
      Returns a function that returns the success side of a given Validation, or this function applied to the failure side.
      default F<A,​Option<B>> optionK()
      Promotes this function so that it returns its result in an Option.
      default P1<B> partial​(A a)
      Partial application.
      default F<A,​Promise<B>> promiseK​(Strategy<Unit> s)
      Promotes this function to a concurrent function that returns a Promise of a value.
      default F<A,​Set<B>> setK​(Ord<B> o)
      Promotes this function to return its value in a Set.
      default F<A,​Stream<B>> streamK()
      Promotes this function so that it returns its result in a Stream.
      default <C> F<A,​Validation<C,​B>> successK()
      Promotes this function so that it returns its result on the success side of an Validation.
      default F<A,​Tree<B>> treeK()
      Promotes this function to return its value in a Tree.
      default F<A,​TreeZipper<B>> treeZipperK()
      Promotes this function to return its value in a TreeZipper.
      default F<A,​Zipper<B>> zipperK()
      Promotes this function to return its value in a Zipper.
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Method Detail

      • f

        B f​(A a)
        Transform A to B.
        Parameters:
        a - The A to transform.
        Returns:
        The result of the transformation.
      • apply

        default B apply​(A a)
        Specified by:
        apply in interface java.util.function.Function<A,​B>
      • o

        default <C> F<C,​B> o​(F<C,​A> g)
        Function composition
        Parameters:
        g - A function to compose with this one.
        Returns:
        The composed function such that this function is applied last.
      • o

        default <C> F<F<C,​A>,​F<C,​B>> o()
        First-class function composition
        Returns:
        A function that composes this function with another.
      • andThen

        default <C> F<A,​C> andThen​(F<B,​C> g)
        Function composition flipped.
        Parameters:
        g - A function with which to compose this one.
        Returns:
        The composed function such that this function is applied first.
      • andThen

        default <C> F<F<B,​C>,​F<A,​C>> andThen()
        First-class composition flipped.
        Returns:
        A function that invokes this function and then a given function on the result.
      • bind

        default <C> F<A,​C> bind​(F<B,​F<A,​C>> g)
        Binds a given function across this function (Reader Monad).
        Parameters:
        g - A function that takes the return value of this function as an argument, yielding a new function.
        Returns:
        A function that invokes this function on its argument and then the given function on the result.
      • bind

        default <C> F<F<B,​F<A,​C>>,​F<A,​C>> bind()
        First-class function binding.
        Returns:
        A function that binds another function across this function.
      • apply

        default <C> F<A,​C> apply​(F<A,​F<B,​C>> g)
        Function application in an environment (Applicative Functor).
        Parameters:
        g - A function with the same argument type as this function, yielding a function that takes the return value of this function.
        Returns:
        A new function that invokes the given function on its argument, yielding a new function that is then applied to the result of applying this function to the argument.
      • apply

        default <C> F<F<A,​F<B,​C>>,​F<A,​C>> apply()
        First-class function application in an environment.
        Returns:
        A function that applies a given function within the environment of this function.
      • on

        default <C> F<A,​F<A,​C>> on​(F<B,​F<B,​C>> g)
        Applies this function over the arguments of another function.
        Parameters:
        g - The function over whose arguments to apply this function.
        Returns:
        A new function that invokes this function on its arguments before invoking the given function.
      • on

        default <C> F<F<B,​F<B,​C>>,​F<A,​F<A,​C>>> on()
        Applies this function over the arguments of another function.
        Returns:
        A function that applies this function over the arguments of another function.
      • lazy

        default F<A,​P1<B>> lazy()
        Promotes this function so that it returns its result in a product-1. Kleisli arrow for P1.
        Returns:
        This function promoted to return its result in a product-1.
      • partial

        default P1<B> partial​(A a)
        Partial application.
        Parameters:
        a - The A to which to apply this function.
        Returns:
        The function partially applied to the given argument to return a lazy value.
      • mapP1

        default F<P1<A>,​P1<B>> mapP1()
        Promotes this function to map over a product-1.
        Returns:
        This function promoted to map over a product-1.
      • optionK

        default F<A,​Option<B>> optionK()
        Promotes this function so that it returns its result in an Option. Kleisli arrow for Option.
        Returns:
        This function promoted to return its result in an Option.
      • mapOption

        default F<Option<A>,​Option<B>> mapOption()
        Promotes this function to map over an optional value.
        Returns:
        This function promoted to map over an optional value.
      • listK

        default F<A,​List<B>> listK()
        Promotes this function so that it returns its result in a List. Kleisli arrow for List.
        Returns:
        This function promoted to return its result in a List.
      • mapList

        default F<List<A>,​List<B>> mapList()
        Promotes this function to map over a List.
        Returns:
        This function promoted to map over a List.
      • streamK

        default F<A,​Stream<B>> streamK()
        Promotes this function so that it returns its result in a Stream. Kleisli arrow for Stream.
        Returns:
        This function promoted to return its result in a Stream.
      • mapStream

        default F<Stream<A>,​Stream<B>> mapStream()
        Promotes this function to map over a Stream.
        Returns:
        This function promoted to map over a Stream.
      • arrayK

        default F<A,​Array<B>> arrayK()
        Promotes this function so that it returns its result in a Array. Kleisli arrow for Array.
        Returns:
        This function promoted to return its result in a Array.
      • mapArray

        default F<Array<A>,​Array<B>> mapArray()
        Promotes this function to map over a Array.
        Returns:
        This function promoted to map over a Array.
      • contramapActor

        default F<Actor<B>,​Actor<A>> contramapActor()
        Returns a function that contramaps over a given actor.
        Returns:
        A function that contramaps over a given actor.
      • promiseK

        default F<A,​Promise<B>> promiseK​(Strategy<Unit> s)
        Promotes this function to a concurrent function that returns a Promise of a value.
        Parameters:
        s - A parallel strategy for concurrent execution.
        Returns:
        A concurrent function that returns a Promise of a value.
      • mapPromise

        default F<Promise<A>,​Promise<B>> mapPromise()
        Promotes this function to map over a Promise.
        Returns:
        This function promoted to map over Promises.
      • eitherLeftK

        default <C> F<A,​Either<B,​C>> eitherLeftK()
        Promotes this function so that it returns its result on the left side of an Either. Kleisli arrow for the Either left projection.
        Returns:
        This function promoted to return its result on the left side of an Either.
      • eitherRightK

        default <C> F<A,​Either<C,​B>> eitherRightK()
        Promotes this function so that it returns its result on the right side of an Either. Kleisli arrow for the Either right projection.
        Returns:
        This function promoted to return its result on the right side of an Either.
      • mapLeft

        default <X> F<Either<A,​X>,​Either<B,​X>> mapLeft()
        Promotes this function to map over the left side of an Either.
        Returns:
        This function promoted to map over the left side of an Either.
      • mapRight

        default <X> F<Either<X,​A>,​Either<X,​B>> mapRight()
        Promotes this function to map over the right side of an Either.
        Returns:
        This function promoted to map over the right side of an Either.
      • onLeft

        default F<Either<B,​A>,​B> onLeft()
        Returns a function that returns the left side of a given Either, or this function applied to the right side.
        Returns:
        a function that returns the left side of a given Either, or this function applied to the right side.
      • onRight

        default F<Either<A,​B>,​B> onRight()
        Returns a function that returns the right side of a given Either, or this function applied to the left side.
        Returns:
        a function that returns the right side of a given Either, or this function applied to the left side.
      • iterableK

        default F<A,​IterableW<B>> iterableK()
        Promotes this function to return its value in an Iterable.
        Returns:
        This function promoted to return its value in an Iterable.
      • mapIterable

        default F<java.lang.Iterable<A>,​IterableW<B>> mapIterable()
        Promotes this function to map over Iterables.
        Returns:
        This function promoted to map over Iterables.
      • nelK

        default F<A,​NonEmptyList<B>> nelK()
        Promotes this function to return its value in a NonEmptyList.
        Returns:
        This function promoted to return its value in a NonEmptyList.
      • mapNel

        default F<NonEmptyList<A>,​NonEmptyList<B>> mapNel()
        Promotes this function to map over a NonEmptyList.
        Returns:
        This function promoted to map over a NonEmptyList.
      • setK

        default F<A,​Set<B>> setK​(Ord<B> o)
        Promotes this function to return its value in a Set.
        Parameters:
        o - An order for the set.
        Returns:
        This function promoted to return its value in a Set.
      • mapSet

        default F<Set<A>,​Set<B>> mapSet​(Ord<B> o)
        Promotes this function to map over a Set.
        Parameters:
        o - An order for the resulting set.
        Returns:
        This function promoted to map over a Set.
      • treeK

        default F<A,​Tree<B>> treeK()
        Promotes this function to return its value in a Tree.
        Returns:
        This function promoted to return its value in a Tree.
      • mapTree

        default F<Tree<A>,​Tree<B>> mapTree()
        Promotes this function to map over a Tree.
        Returns:
        This function promoted to map over a Tree.
      • foldMapTree

        default F<Tree<A>,​B> foldMapTree​(Monoid<B> m)
        Returns a function that maps this function over a tree and folds it with the given monoid.
        Parameters:
        m - The monoid with which to fold the mapped tree.
        Returns:
        a function that maps this function over a tree and folds it with the given monoid.
      • treeZipperK

        default F<A,​TreeZipper<B>> treeZipperK()
        Promotes this function to return its value in a TreeZipper.
        Returns:
        This function promoted to return its value in a TreeZipper.
      • mapTreeZipper

        default F<TreeZipper<A>,​TreeZipper<B>> mapTreeZipper()
        Promotes this function to map over a TreeZipper.
        Returns:
        This function promoted to map over a TreeZipper.
      • failK

        default <C> F<A,​Validation<B,​C>> failK()
        Promotes this function so that it returns its result on the failure side of a Validation. Kleisli arrow for the Validation failure projection.
        Returns:
        This function promoted to return its result on the failure side of a Validation.
      • successK

        default <C> F<A,​Validation<C,​B>> successK()
        Promotes this function so that it returns its result on the success side of an Validation. Kleisli arrow for the Validation success projection.
        Returns:
        This function promoted to return its result on the success side of an Validation.
      • mapFail

        default <X> F<Validation<A,​X>,​Validation<B,​X>> mapFail()
        Promotes this function to map over the failure side of a Validation.
        Returns:
        This function promoted to map over the failure side of a Validation.
      • mapSuccess

        default <X> F<Validation<X,​A>,​Validation<X,​B>> mapSuccess()
        Promotes this function to map over the success side of a Validation.
        Returns:
        This function promoted to map over the success side of a Validation.
      • onFail

        default F<Validation<B,​A>,​B> onFail()
        Returns a function that returns the failure side of a given Validation, or this function applied to the success side.
        Returns:
        a function that returns the failure side of a given Validation, or this function applied to the success side.
      • onSuccess

        default F<Validation<A,​B>,​B> onSuccess()
        Returns a function that returns the success side of a given Validation, or this function applied to the failure side.
        Returns:
        a function that returns the success side of a given Validation, or this function applied to the failure side.
      • zipperK

        default F<A,​Zipper<B>> zipperK()
        Promotes this function to return its value in a Zipper.
        Returns:
        This function promoted to return its value in a Zipper.
      • mapZipper

        default F<Zipper<A>,​Zipper<B>> mapZipper()
        Promotes this function to map over a Zipper.
        Returns:
        This function promoted to map over a Zipper.
      • contramapEqual

        default F<Equal<B>,​Equal<A>> contramapEqual()
        Promotes this function to map over an Equal as a contravariant functor.
        Returns:
        This function promoted to map over an Equal as a contravariant functor.
      • contramapHash

        default F<Hash<B>,​Hash<A>> contramapHash()
        Promotes this function to map over a Hash as a contravariant functor.
        Returns:
        This function promoted to map over a Hash as a contravariant functor.
      • contramapShow

        default F<Show<B>,​Show<A>> contramapShow()
        Promotes this function to map over a Show as a contravariant functor.
        Returns:
        This function promoted to map over a Show as a contravariant functor.
      • mapFst

        default <C> F<P2<A,​C>,​P2<B,​C>> mapFst()
        Promotes this function to map over the first element of a pair.
        Returns:
        This function promoted to map over the first element of a pair.
      • mapSnd

        default <C> F<P2<C,​A>,​P2<C,​B>> mapSnd()
        Promotes this function to map over the second element of a pair.
        Returns:
        This function promoted to map over the second element of a pair.
      • mapBoth

        default F<P2<A,​A>,​P2<B,​B>> mapBoth()
        Promotes this function to map over both elements of a pair.
        Returns:
        This function promoted to map over both elements of a pair.
      • mapJ

        default java.util.concurrent.SynchronousQueue<B> mapJ​(java.util.concurrent.SynchronousQueue<A> as)
        Maps this function over a SynchronousQueue.
        Parameters:
        as - A SynchronousQueue to map this function over.
        Returns:
        A new SynchronousQueue with this function applied to each element.
      • mapJ

        default java.util.concurrent.PriorityBlockingQueue<B> mapJ​(java.util.concurrent.PriorityBlockingQueue<A> as)
        Maps this function over a PriorityBlockingQueue.
        Parameters:
        as - A PriorityBlockingQueue to map this function over.
        Returns:
        A new PriorityBlockingQueue with this function applied to each element.
      • mapJ

        default java.util.concurrent.LinkedBlockingQueue<B> mapJ​(java.util.concurrent.LinkedBlockingQueue<A> as)
        Maps this function over a LinkedBlockingQueue.
        Parameters:
        as - A LinkedBlockingQueue to map this function over.
        Returns:
        A new LinkedBlockingQueue with this function applied to each element.
      • mapJ

        default java.util.concurrent.CopyOnWriteArraySet<B> mapJ​(java.util.concurrent.CopyOnWriteArraySet<A> as)
        Maps this function over a CopyOnWriteArraySet.
        Parameters:
        as - A CopyOnWriteArraySet to map this function over.
        Returns:
        A new CopyOnWriteArraySet with this function applied to each element.
      • mapJ

        default java.util.concurrent.CopyOnWriteArrayList<B> mapJ​(java.util.concurrent.CopyOnWriteArrayList<A> as)
        Maps this function over a CopyOnWriteArrayList.
        Parameters:
        as - A CopyOnWriteArrayList to map this function over.
        Returns:
        A new CopyOnWriteArrayList with this function applied to each element.
      • mapJ

        default java.util.concurrent.ConcurrentLinkedQueue<B> mapJ​(java.util.concurrent.ConcurrentLinkedQueue<A> as)
        Maps this function over a ConcurrentLinkedQueue.
        Parameters:
        as - A ConcurrentLinkedQueue to map this function over.
        Returns:
        A new ConcurrentLinkedQueue with this function applied to each element.
      • mapJ

        default java.util.concurrent.ArrayBlockingQueue<B> mapJ​(java.util.concurrent.ArrayBlockingQueue<A> as)
        Maps this function over an ArrayBlockingQueue.
        Parameters:
        as - An ArrayBlockingQueue to map this function over.
        Returns:
        A new ArrayBlockingQueue with this function applied to each element.
      • mapJ

        default java.util.TreeSet<B> mapJ​(java.util.TreeSet<A> as)
        Maps this function over a TreeSet.
        Parameters:
        as - A TreeSet to map this function over.
        Returns:
        A new TreeSet with this function applied to each element.
      • mapJ

        default java.util.PriorityQueue<B> mapJ​(java.util.PriorityQueue<A> as)
        Maps this function over a PriorityQueue.
        Parameters:
        as - A PriorityQueue to map this function over.
        Returns:
        A new PriorityQueue with this function applied to each element.
      • mapJ

        default java.util.LinkedList<B> mapJ​(java.util.LinkedList<A> as)
        Maps this function over a LinkedList.
        Parameters:
        as - A LinkedList to map this function over.
        Returns:
        A new LinkedList with this function applied to each element.
      • mapJ

        default java.util.ArrayList<B> mapJ​(java.util.ArrayList<A> as)
        Maps this function over an ArrayList.
        Parameters:
        as - An ArrayList to map this function over.
        Returns:
        A new ArrayList with this function applied to each element.
      • map

        default <C> F<A,​C> map​(F<B,​C> f)
      • contramap

        default <C> F<C,​B> contramap​(F<C,​A> f)
      • dimap

        default <C,​D> F<C,​D> dimap​(F<C,​A> f,
                                               F<B,​D> g)
        Both map (with g) and contramap (with f) the target function. (Profunctor pattern)