Package fj

Class P2<A,B>

java.lang.Object
fj.P2<A,B>

public abstract class P2<A,B> extends Object
A product-2.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Optic factory methods for a P2
  • Constructor Summary

    Constructors
    Constructor
    Description
    P2()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A, B> F<P2<A,B>,A>
    __1()
    Returns a function that returns the first element of a product.
    static <A, B> F<P2<A,B>,B>
    __2()
    Returns a function that returns the second element of a product.
    abstract A
    _1()
    Access the first element of the product.
    final P1<A>
    _1_()
    Returns the 1-product projection over the first element.
    abstract B
    _2()
    Access the second element of the product.
    final P1<B>
    _2_()
    Returns the 1-product projection over the second element.
    final <C> P3<A,B,C>
    append(C el)
    Creates a P3 by adding the given element to the current P2
    final <C, D> P4<A,B,C,D>
    append(P2<C,D> el)
    Creates a P4 by adding the given element to the current P2
    final <C, D, E> P5<A,B,C,D,E>
    append(P3<C,D,E> el)
    Creates a P5 by adding the given element to the current P2
    final <C, D, E, F>
    P6<A,B,C,D,E,F>
    append(P4<C,D,E,F> el)
    Creates a P6 by adding the given element to the current P2
    final <C, D, E, F, G>
    P7<A,B,C,D,E,F,G>
    append(P5<C,D,E,F,G> el)
    Creates a P7 by adding the given element to the current P2
    final <C, D, E, F, G, H>
    P8<A,B,C,D,E,F,G,H>
    append(P6<C,D,E,F,G,H> el)
    Creates a P8 by adding the given element to the current P2
    final <C> P2<C,B>
    cobind(F<P2<A,B>,C> k)
    Duplicates this product on the first element, and maps the given function across the duplicate (Comonad pattern).
    final P2<P2<A,B>,B>
    Duplicates this product into the first element (Comonad pattern).
    final boolean
    equals(Object other)
     
    static <B, C, D> P2<C,D>
    fanout(F<B,C> f, F<B,D> g, B b)
    Sends the given input value to both argument functions and combines their output.
    final int
     
    final <C> P2<C,B>
    inject(C c)
    Replaces the first element of this product with the given value.
    static <A, B> P2<B,B>
    map(F<A,B> f, P2<A,A> p)
    Maps the given function across both the elements of the given product.
    final <X> P2<X,B>
    map1(F<A,X> f)
    Map the first element of the product.
    static <A, B, X> F<P2<A,B>,P2<X,B>>
    map1_(F<A,X> f)
    Promotes a function so that it maps the first element of a product.
    final <X> P2<A,X>
    map2(F<B,X> f)
    Map the second element of the product.
    static <A, B, X> F<P2<A,B>,P2<A,X>>
    map2_(F<B,X> f)
    Promotes a function so that it maps the second element of a product.
    final P2<A,B>
    Provides a memoising P2 that remembers its values.
    final <C> List<C>
    sequenceW(List<F<P2<A,B>,C>> fs)
    Applies a list of comonadic functions to this product, returning a list of values.
    final <C> Stream<C>
    sequenceW(Stream<F<P2<A,B>,C>> fs)
    Applies a stream of comonadic functions to this product, returning a stream of values.
    final <C, D> P2<C,D>
    split(F<A,C> f, F<B,D> g)
    Split this product between two argument functions and combine their output.
    static <A, B, C, D>
    F<P2<A,B>,P2<C,D>>
    split_(F<A,C> f, F<B,D> g)
    A first-class version of the split function.
    final P2<B,A>
    Swaps the elements around in this product.
    static <A, B> F<P2<A,B>,P2<B,A>>
    Returns a curried form of swap().
    final String
     
    final <C, X> Either<X,P2<A,C>>
     
    final <C> IO<P2<A,C>>
    traverseIO(F<B,IO<C>> f)
     
    final <C> List<P2<A,C>>
     
    final <C> Option<P2<A,C>>
     
    final <C> Stream<P2<A,C>>
     
    static <A, B, C> F<P2<A,B>,C>
    tuple(F<A,F<B,C>> f)
    Transforms a curried function of arity-2 to a function of a product-2
    static <A, B, C> F<P2<A,B>,C>
    tuple(F2<A,B,C> f)
    Transforms an uncurried function of arity-2 to a function of a product-2
    static <A, B, C> F2<A,B,C>
    untuple(F<P2<A,B>,C> f)
    Transforms a function of a product-2 to an uncurried function or arity-2.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • P2

      public P2()
  • Method Details

    • _1

      public abstract A _1()
      Access the first element of the product.
      Returns:
      The first element of the product.
    • _2

      public abstract B _2()
      Access the second element of the product.
      Returns:
      The second element of the product.
    • equals

      public final boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • swap

      public final P2<B,A> swap()
      Swaps the elements around in this product.
      Returns:
      A new product-2 with the elements swapped.
    • map1

      public final <X> P2<X,B> map1(F<A,X> f)
      Map the first element of the product.
      Parameters:
      f - The function to map with.
      Returns:
      A product with the given function applied.
    • map2

      public final <X> P2<A,X> map2(F<B,X> f)
      Map the second element of the product.
      Parameters:
      f - The function to map with.
      Returns:
      A product with the given function applied.
    • split

      public final <C, D> P2<C,D> split(F<A,C> f, F<B,D> g)
      Split this product between two argument functions and combine their output.
      Parameters:
      f - A function that will map the first element of this product.
      g - A function that will map the second element of this product.
      Returns:
      A new product with the first function applied to the second element and the second function applied to the second element.
    • cobind

      public final <C> P2<C,B> cobind(F<P2<A,B>,C> k)
      Duplicates this product on the first element, and maps the given function across the duplicate (Comonad pattern).
      Parameters:
      k - A function to map over the duplicated product.
      Returns:
      A new product with the result of the given function applied to this product as the first element, and with the second element intact.
    • duplicate

      public final P2<P2<A,B>,B> duplicate()
      Duplicates this product into the first element (Comonad pattern).
      Returns:
      A new product with this product in its first element and with the second element intact.
    • inject

      public final <C> P2<C,B> inject(C c)
      Replaces the first element of this product with the given value.
      Parameters:
      c - The value with which to replace the first element of this product.
      Returns:
      A new product with the first element replaced with the given value.
    • sequenceW

      public final <C> List<C> sequenceW(List<F<P2<A,B>,C>> fs)
      Applies a list of comonadic functions to this product, returning a list of values.
      Parameters:
      fs - A list of functions to apply to this product.
      Returns:
      A list of the results of applying the given list of functions to this product.
    • traverseList

      public final <C> List<P2<A,C>> traverseList(F<B,List<C>> f)
    • traverseStream

      public final <C> Stream<P2<A,C>> traverseStream(F<B,Stream<C>> f)
    • traverseIO

      public final <C> IO<P2<A,C>> traverseIO(F<B,IO<C>> f)
    • traverseOption

      public final <C> Option<P2<A,C>> traverseOption(F<B,Option<C>> f)
    • traverseEither

      public final <C, X> Either<X,P2<A,C>> traverseEither(F<B,Either<X,C>> f)
    • sequenceW

      public final <C> Stream<C> sequenceW(Stream<F<P2<A,B>,C>> fs)
      Applies a stream of comonadic functions to this product, returning a stream of values.
      Parameters:
      fs - A stream of functions to apply to this product.
      Returns:
      A stream of the results of applying the given stream of functions to this product.
    • _1_

      public final P1<A> _1_()
      Returns the 1-product projection over the first element.
      Returns:
      the 1-product projection over the first element.
    • _2_

      public final P1<B> _2_()
      Returns the 1-product projection over the second element.
      Returns:
      the 1-product projection over the second element.
    • append

      public final <C> P3<A,B,C> append(C el)
      Creates a P3 by adding the given element to the current P2
      Parameters:
      el - the element to append
      Returns:
      A P3 containing the original P2 with the extra element added at the end
    • append

      public final <C, D> P4<A,B,C,D> append(P2<C,D> el)
      Creates a P4 by adding the given element to the current P2
      Parameters:
      el - the element to append
      Returns:
      A P4 containing the original P2 with the extra element added at the end
    • append

      public final <C, D, E> P5<A,B,C,D,E> append(P3<C,D,E> el)
      Creates a P5 by adding the given element to the current P2
      Parameters:
      el - the element to append
      Returns:
      A P5 containing the original P2 with the extra element added at the end
    • append

      public final <C, D, E, F> P6<A,B,C,D,E,F> append(P4<C,D,E,F> el)
      Creates a P6 by adding the given element to the current P2
      Parameters:
      el - the element to append
      Returns:
      A P6 containing the original P2 with the extra element added at the end
    • append

      public final <C, D, E, F, G> P7<A,B,C,D,E,F,G> append(P5<C,D,E,F,G> el)
      Creates a P7 by adding the given element to the current P2
      Parameters:
      el - the element to append
      Returns:
      A P7 containing the original P2 with the extra element added at the end
    • append

      public final <C, D, E, F, G, H> P8<A,B,C,D,E,F,G,H> append(P6<C,D,E,F,G,H> el)
      Creates a P8 by adding the given element to the current P2
      Parameters:
      el - the element to append
      Returns:
      A P8 containing the original P2 with the extra element added at the end
    • memo

      public final P2<A,B> memo()
      Provides a memoising P2 that remembers its values.
      Returns:
      A P2 that calls this P2 once for any given element and remembers the value for subsequent calls.
    • split_

      public static <A, B, C, D> F<P2<A,B>,P2<C,D>> split_(F<A,C> f, F<B,D> g)
      A first-class version of the split function.
      Parameters:
      f - A function that will map the first element of the given product.
      g - A function that will map the second element of the given product.
      Returns:
      A function that splits a given product between the two given functions and combines their output.
    • map1_

      public static <A, B, X> F<P2<A,B>,P2<X,B>> map1_(F<A,X> f)
      Promotes a function so that it maps the first element of a product.
      Parameters:
      f - The function to promote.
      Returns:
      The given function, promoted to map the first element of products.
    • map2_

      public static <A, B, X> F<P2<A,B>,P2<A,X>> map2_(F<B,X> f)
      Promotes a function so that it maps the second element of a product.
      Parameters:
      f - The function to promote.
      Returns:
      The given function, promoted to map the second element of products.
    • fanout

      public static <B, C, D> P2<C,D> fanout(F<B,C> f, F<B,D> g, B b)
      Sends the given input value to both argument functions and combines their output.
      Parameters:
      f - A function to receive an input value.
      g - A function to receive an input value.
      b - An input value to send to both functions.
      Returns:
      The product of the two functions applied to the input value.
    • map

      public static <A, B> P2<B,B> map(F<A,B> f, P2<A,A> p)
      Maps the given function across both the elements of the given product.
      Parameters:
      f - A function to map over a product.
      p - A product over which to map.
      Returns:
      A new product with the given function applied to both elements.
    • swap_

      public static <A, B> F<P2<A,B>,P2<B,A>> swap_()
      Returns a curried form of swap().
      Returns:
      A curried form of swap().
    • __1

      public static <A, B> F<P2<A,B>,A> __1()
      Returns a function that returns the first element of a product.
      Returns:
      A function that returns the first element of a product.
    • __2

      public static <A, B> F<P2<A,B>,B> __2()
      Returns a function that returns the second element of a product.
      Returns:
      A function that returns the second element of a product.
    • tuple

      public static <A, B, C> F<P2<A,B>,C> tuple(F<A,F<B,C>> f)
      Transforms a curried function of arity-2 to a function of a product-2
      Parameters:
      f - a curried function of arity-2 to transform into a function of a product-2
      Returns:
      The function, transformed to operate on on a product-2
    • tuple

      public static <A, B, C> F<P2<A,B>,C> tuple(F2<A,B,C> f)
      Transforms an uncurried function of arity-2 to a function of a product-2
      Parameters:
      f - an uncurried function of arity-2 to transform into a function of a product-2
      Returns:
      The function, transformed to operate on on a product-2
    • untuple

      public static <A, B, C> F2<A,B,C> untuple(F<P2<A,B>,C> f)
      Transforms a function of a product-2 to an uncurried function or arity-2.
      Parameters:
      f - A function of a product-2 to transform into an uncurried function.
      Returns:
      The function, transformed to an uncurried function of arity-2.
    • toString

      public final String toString()
      Overrides:
      toString in class Object