Package fj

Class P1<A>

All Implemented Interfaces:
F0<A>, Supplier<A>
Direct Known Subclasses:
$, P1.Memo, P1.ReferenceMemo

public abstract class P1<A> extends Object implements F0<A>
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static final class 
     
    (package private) static class 
     
    (package private) static final class 
     
    (package private) static final class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    P1()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A> F<P1<A>,A>
    __1()
    Returns a function that returns the first element of a product.
    abstract A
    _1()
    Access the first element of the product.
    final <B> P1<B>
    apply(P1<F<A,B>> cf)
    Performs function application within a P1 (applicative functor pattern).
    final <B> P1<B>
    bind(F<A,P1<B>> f)
    Binds the given function to the value in a product-1 with a final join.
    final <B, C> P1<C>
    bind(P1<B> cb, F<A,F<B,C>> f)
    Binds the given function to the values in the given P1s with a final join.
    final <B, C> P1<C>
    bind(P1<B> cb, F2<A,B,C> f)
    Binds the given function to the values in the given P1s with a final join.
    final <B> F<B,A>
    Returns a constant function that always uses this value.
    static <A, B> F<A,P1<B>>
    curry(F<A,B> f)
    Promotes the given function so that it returns its value in a P1.
    final boolean
    equals(Object other)
     
    final A
    f()
     
    P1<A>
    Returns a P1 that remembers its value.
    final int
     
    static <A> P1<A>
    join(P1<P1<A>> a)
    Joins a P1 of a P1 with a bind operation.
    static <A, B, C> F<P1<A>,F<P1<B>,P1<C>>>
    liftM2(F<A,F<B,C>> f)
    Promotes a function of arity-2 to a function on P1s.
    final <B, C> P1<C>
    liftM2(P1<B> pb, F2<A,B,C> f)
     
    final <B> P1<B>
    map(F<A,B> f)
    Map the element of the product.
    static <A, B> F<P1<A>,P1<B>>
    map_(F<A,B> f)
    Promote any function to a transformation between P1s.
    final P1<A>
    Wrap the memoized value into a WeakReference.
    static <A> P1<Array<A>>
    sequence(Array<P1<A>> as)
    Turns an array of P1s into a single P1 of an array.
    static <A> P1<List<A>>
    sequence(List<P1<A>> as)
    Turns a List of P1s into a single P1 of a List.
    static <A> P1<Option<A>>
    Turns an optional P1 into a lazy option.
    static <A> P1<Stream<A>>
    sequence(Stream<P1<A>> as)
    Turns a stream of P1s into a single P1 of a stream.
    static <A> F<List<P1<A>>,P1<List<A>>>
    A first-class version of the sequence method for lists of P1s.
    P1<A>
    Like memo, but the memoized value is wrapped into a SoftReference
    final String
     
    final <B, X> Either<X,P1<B>>
    Traversable instance of P1 for Either
    final <B> List<P1<B>>
    Traversable instance of P1 for List
    final <B> Option<P1<B>>
    Traversable instance of P1 for Option
    final <B> Stream<P1<B>>
    Traversable instance of P1 for Stream
    final <B, E> Validation<E,P1<B>>
    Traversable instance of P1 for Validation
    P1<A>
    Like memo, but the memoized value is wrapped into a WeakReference

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface fj.F0

    get, toEffect0, toP1, toTry0, toTryEffect0
  • Constructor Details

    • P1

      public P1()
  • Method Details

    • f

      public final A f()
      Specified by:
      f in interface F0<A>
    • _1

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

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

      public static <A, B> F<P1<A>,P1<B>> map_(F<A,B> f)
      Promote any function to a transformation between P1s.
      Parameters:
      f - A function to promote to a transformation between P1s.
      Returns:
      A function promoted to operate on P1s.
    • bind

      public final <B> P1<B> bind(F<A,P1<B>> f)
      Binds the given function to the value in a product-1 with a final join.
      Parameters:
      f - A function to apply to the value in a product-1.
      Returns:
      The result of applying the given function to the value of given product-1.
    • curry

      public static <A, B> F<A,P1<B>> curry(F<A,B> f)
      Promotes the given function so that it returns its value in a P1.
      Parameters:
      f - A function to have its result wrapped in a P1.
      Returns:
      A function whose result is wrapped in a P1.
    • apply

      public final <B> P1<B> apply(P1<F<A,B>> cf)
      Performs function application within a P1 (applicative functor pattern).
      Parameters:
      cf - The P1 function to apply.
      Returns:
      A new P1 after applying the given P1 function to the first argument.
    • bind

      public final <B, C> P1<C> bind(P1<B> cb, F<A,F<B,C>> f)
      Binds the given function to the values in the given P1s with a final join.
      Parameters:
      cb - A given P1 to bind the given function with.
      f - The function to apply to the values in the given P1s.
      Returns:
      A new P1 after performing the map, then final join.
    • bind

      public final <B, C> P1<C> bind(P1<B> cb, F2<A,B,C> f)
      Binds the given function to the values in the given P1s with a final join.
    • join

      public static <A> P1<A> join(P1<P1<A>> a)
      Joins a P1 of a P1 with a bind operation.
      Parameters:
      a - The P1 of a P1 to join.
      Returns:
      A new P1 that is the join of the given P1.
    • liftM2

      public static <A, B, C> F<P1<A>,F<P1<B>,P1<C>>> liftM2(F<A,F<B,C>> f)
      Promotes a function of arity-2 to a function on P1s.
      Parameters:
      f - The function to promote.
      Returns:
      A function of arity-2 promoted to map over P1s.
    • liftM2

      public final <B, C> P1<C> liftM2(P1<B> pb, F2<A,B,C> f)
    • sequence

      public static <A> P1<List<A>> sequence(List<P1<A>> as)
      Turns a List of P1s into a single P1 of a List.
      Parameters:
      as - The list of P1s to transform.
      Returns:
      A single P1 for the given List.
    • sequenceList

      public static <A> F<List<P1<A>>,P1<List<A>>> sequenceList()
      A first-class version of the sequence method for lists of P1s.
      Returns:
      A function from a List of P1s to a single P1 of a List.
    • sequence

      public static <A> P1<Stream<A>> sequence(Stream<P1<A>> as)
      Turns a stream of P1s into a single P1 of a stream.
      Parameters:
      as - The stream of P1s to transform.
      Returns:
      A single P1 for the given stream.
    • sequence

      public static <A> P1<Option<A>> sequence(Option<P1<A>> o)
      Turns an optional P1 into a lazy option.
    • sequence

      public static <A> P1<Array<A>> sequence(Array<P1<A>> as)
      Turns an array of P1s into a single P1 of an array.
      Parameters:
      as - The array of P1s to transform.
      Returns:
      A single P1 for the given array.
    • traverseList

      public final <B> List<P1<B>> traverseList(F<A,List<B>> f)
      Traversable instance of P1 for List
      Parameters:
      f - The function that takes A and produces a List (non-deterministic result)
      Returns:
      A List of P1
    • traverseEither

      public final <B, X> Either<X,P1<B>> traverseEither(F<A,Either<X,B>> f)
      Traversable instance of P1 for Either
      Parameters:
      f - The function produces Either
      Returns:
      An Either of P1
    • traverseOption

      public final <B> Option<P1<B>> traverseOption(F<A,Option<B>> f)
      Traversable instance of P1 for Option
      Parameters:
      f - The function that produces Option
      Returns:
      An Option of P1
    • traverseValidation

      public final <B, E> Validation<E,P1<B>> traverseValidation(F<A,Validation<E,B>> f)
      Traversable instance of P1 for Validation
      Parameters:
      f - The function might produces Validation
      Returns:
      An Validation of P1
    • traverseStream

      public final <B> Stream<P1<B>> traverseStream(F<A,Stream<B>> f)
      Traversable instance of P1 for Stream
      Parameters:
      f - The function that produces Stream
      Returns:
      An Stream of P1
    • map

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

      public final P1<A> memo()
      Wrap the memoized value into a WeakReference.
    • hardMemo

      public P1<A> hardMemo()
      Returns a P1 that remembers its value.
      Returns:
      A P1 that calls this P1 once and remembers the value for subsequent calls.
    • weakMemo

      public P1<A> weakMemo()
      Like memo, but the memoized value is wrapped into a WeakReference
    • softMemo

      public P1<A> softMemo()
      Like memo, but the memoized value is wrapped into a SoftReference
    • constant

      public final <B> F<B,A> constant()
      Returns a constant function that always uses this value.
      Returns:
      A constant function that always uses this value.
    • toString

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

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

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