com.jnape.palatable.lambda.adt.choice

## Class Choice3<A,B,C>

- java.lang.Object
- - com.jnape.palatable.lambda.adt.choice.Choice3<A,B,C>

- Type Parameters:
    `A` - the first possible type
    `B` - the second possible type
    `C` - the third possible type
  All Implemented Interfaces:
    CoProduct3<A,B,C,Choice3<A,B,C>>, Applicative<C,Choice3<A,B,?>>, Bifunctor<B,C,Choice3<A,?,?>>, BoundedBifunctor<B,C,Object,Object,Choice3<A,?,?>>, Functor<C,Choice3<A,B,?>>, Monad<C,Choice3<A,B,?>>, MonadRec<C,Choice3<A,B,?>>, Traversable<C,Choice3<A,B,?>>

      public abstract class Choice3<A,B,C>
      extends Object
      implements CoProduct3<A,B,C,Choice3<A,B,C>>, MonadRec<C,Choice3<A,B,?>>, Bifunctor<B,C,Choice3<A,?,?>>, Traversable<C,Choice3<A,B,?>>

  Canonical ADT representation of `CoProduct3`.
  See Also:
    `Choice2`, `Choice4`

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <A,B,C> Choice3<A,B,C>` | `a(A a)` Static factory method for wrapping a value of type `A` in a `Choice3`.
    `static <A,B,C> Choice3<A,B,C>` | `b(B b)` Static factory method for wrapping a value of type `A` in a `Choice3`.
    `<D,E> Choice3<A,D,E>` | `biMap(Fn1<? super B,? extends D> lFn, Fn1<? super C,? extends E> rFn)` Dually map covariantly over both the left and right parameters.
    `<D> Choice3<A,D,C>` | `biMapL(Fn1<? super B,? extends D> fn)` Covariantly map over the left parameter.
    `<D> Choice3<A,B,D>` | `biMapR(Fn1<? super C,? extends D> fn)` Covariantly map over the right parameter.
    `static <A,B,C> Choice3<A,B,C>` | `c(C c)` Static factory method for wrapping a value of type `A` in a `Choice3`.
    `Choice2<A,B>` | `converge(Fn1<? super C,? extends CoProduct2<A,B,?>> convergenceFn)` Converge this coproduct down to a lower order coproduct by mapping the last possible type into an earlier possible type.
    `<D> Choice3<A,B,D>` | `discardL(Applicative<D,Choice3<A,B,?>> appB)` Sequence both this `Applicative` and `appB`, discarding this `Applicative's` result and returning `appB`.
    `<D> Choice3<A,B,C>` | `discardR(Applicative<D,Choice3<A,B,?>> appB)` Sequence both this `Applicative` and `appB`, discarding `appB's` result and returning this `Applicative`.
    `<D> Choice4<A,B,C,D>` | `diverge()` Diverge this coproduct by introducing another possible type that it could represent.
    `<D> Choice3<A,B,D>` | `flatMap(Fn1<? super C,? extends Monad<D,Choice3<A,B,?>>> f)` Chain dependent computations that may continue or short-circuit based on previous results.
    `<D> Choice3<A,B,D>` | `fmap(Fn1<? super C,? extends D> fn)` Covariantly transmute this functor's parameter using the given mapping function.
    `<D> Lazy<Choice3<A,B,D>>` | `lazyZip(Lazy<? extends Applicative<Fn1<? super C,? extends D>,Choice3<A,B,?>>> lazyAppFn)` Given a `lazy` instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
    `Tuple3<Maybe<A>,Maybe<B>,Maybe<C>>` | `project()` Specialize this choice's projection to a `Tuple3`.
    `<D> Choice3<A,B,D>` | `pure(D d)` Lift the value `b` into this applicative functor.
    `static <A,B> Pure<Choice3<A,B,?>>` | `pureChoice()` The canonical `Pure` instance for `Choice3`.
    `<D> Choice3<A,B,D>` | `trampolineM(Fn1<? super C,? extends MonadRec<RecursiveResult<C,D>,Choice3<A,B,?>>> fn)` Given some operation yielding a `RecursiveResult` inside this `MonadRec`, internally trampoline the operation until it yields a `termination` instruction.
    `<D,App extends Applicative<?,App>,TravB extends Traversable<D,Choice3<A,B,?>>,AppTrav extends Applicative<TravB,App>> AppTrav` | `traverse(Fn1<? super C,? extends Applicative<D,App>> fn, Fn1<? super TravB,? extends AppTrav> pure)` Apply `fn` to each element of this traversable from left to right, and collapse the results into a single resulting applicative, potentially with the assistance of the applicative's pure function.
    `<D> Choice3<A,B,D>` | `zip(Applicative<Fn1<? super C,? extends D>,Choice3<A,B,?>> appFn)` Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.jnape.palatable.lambda.adt.coproduct.CoProduct3

      `embed, match, projectA, projectB, projectC`

    - ### Methods inherited from interface com.jnape.palatable.lambda.monad.Monad

      `join`

    - ### Methods inherited from interface com.jnape.palatable.lambda.functor.Functor

      `coerce`

- - ### Method Detail

    - #### project

          public Tuple3<Maybe<A>,Maybe<B>,Maybe<C>> project()

      Specialize this choice's projection to a `Tuple3`.
      Specified by:
        `project` in interface `CoProduct3<A,B,C,Choice3<A,B,C>>`
      Returns:
        a `Tuple3`
      See Also:
        `CoProduct2.project()`

    - #### diverge

          public final <D> Choice4<A,B,C,D> diverge()

      Diverge this coproduct by introducing another possible type that it could represent.
      Specified by:
        `diverge` in interface `CoProduct3<A,B,C,Choice3<A,B,C>>`
      Type Parameters:
        `D` - the additional possible type of this coproduct
      Returns:
        a `CoProduct4`<A, B, C, D>
      See Also:
        `CoProduct2.diverge()`

    - #### converge

          public final Choice2<A,B> converge(Fn1<? super C,? extends CoProduct2<A,B,?>> convergenceFn)

      Converge this coproduct down to a lower order coproduct by mapping the last possible type into an earlier possible type. This is the categorical dual of `CoProduct2.diverge()`, which introduces the type `C` and raises the order from 2 to 3.

      The following laws hold for any two coproducts of single order difference:

      - Cancellation: `coProductN.diverge().converge(CoProductN::a) == coProductN`
      Specified by:
        `converge` in interface `CoProduct3<A,B,C,Choice3<A,B,C>>`
      Parameters:
        `convergenceFn` - function from last possible type to earlier type
      Returns:
        a `CoProduct2`<A, B>

    - #### fmap

          public final <D> Choice3<A,B,D> fmap(Fn1<? super C,? extends D> fn)

      Covariantly transmute this functor's parameter using the given mapping function. Generally this method is specialized to return an instance of the class implementing Functor.
      Specified by:
        `fmap` in interface `Applicative<C,Choice3<A,B,?>>`
      Specified by:
        `fmap` in interface `Functor<C,Choice3<A,B,?>>`
      Specified by:
        `fmap` in interface `Monad<C,Choice3<A,B,?>>`
      Specified by:
        `fmap` in interface `MonadRec<C,Choice3<A,B,?>>`
      Specified by:
        `fmap` in interface `Traversable<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the new parameter type
      Parameters:
        `fn` - the mapping function
      Returns:
        a functor over B (the new parameter type)

    - #### biMapL

          public final <D> Choice3<A,D,C> biMapL(Fn1<? super B,? extends D> fn)

      Covariantly map over the left parameter.
      Specified by:
        `biMapL` in interface `Bifunctor<B,C,Choice3<A,?,?>>`
      Specified by:
        `biMapL` in interface `BoundedBifunctor<B,C,Object,Object,Choice3<A,?,?>>`
      Type Parameters:
        `D` - the new left parameter type
      Parameters:
        `fn` - the mapping function
      Returns:
        a bifunctor over C (the new left parameter) and B (the same right parameter)

    - #### biMapR

          public final <D> Choice3<A,B,D> biMapR(Fn1<? super C,? extends D> fn)

      Covariantly map over the right parameter. For all bifunctors that are also functors, it should hold that `biMapR(f) == fmap(f)`.
      Specified by:
        `biMapR` in interface `Bifunctor<B,C,Choice3<A,?,?>>`
      Specified by:
        `biMapR` in interface `BoundedBifunctor<B,C,Object,Object,Choice3<A,?,?>>`
      Type Parameters:
        `D` - the new right parameter type
      Parameters:
        `fn` - the mapping function
      Returns:
        a bifunctor over A (the same left parameter) and C (the new right parameter)

    - #### biMap

          public final <D,E> Choice3<A,D,E> biMap(Fn1<? super B,? extends D> lFn,
                                                  Fn1<? super C,? extends E> rFn)

      Dually map covariantly over both the left and right parameters. This is isomorphic to `biMapL(lFn).biMapR(rFn)`.
      Specified by:
        `biMap` in interface `Bifunctor<B,C,Choice3<A,?,?>>`
      Specified by:
        `biMap` in interface `BoundedBifunctor<B,C,Object,Object,Choice3<A,?,?>>`
      Type Parameters:
        `D` - the new left parameter type
        `E` - the new right parameter type
      Parameters:
        `lFn` - the left parameter mapping function
        `rFn` - the right parameter mapping function
      Returns:
        a bifunctor over C (the new left parameter type) and D (the new right parameter type)

    - #### pure

          public <D> Choice3<A,B,D> pure(D d)

      Lift the value `b` into this applicative functor.
      Specified by:
        `pure` in interface `Applicative<C,Choice3<A,B,?>>`
      Specified by:
        `pure` in interface `Monad<C,Choice3<A,B,?>>`
      Specified by:
        `pure` in interface `MonadRec<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the type of the returned applicative's parameter
      Parameters:
        `d` - the value
      Returns:
        an instance of this applicative over b

    - #### zip

          public <D> Choice3<A,B,D> zip(Applicative<Fn1<? super C,? extends D>,Choice3<A,B,?>> appFn)

      Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
      Specified by:
        `zip` in interface `Applicative<C,Choice3<A,B,?>>`
      Specified by:
        `zip` in interface `Monad<C,Choice3<A,B,?>>`
      Specified by:
        `zip` in interface `MonadRec<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the resulting applicative parameter type
      Parameters:
        `appFn` - the other applicative instance
      Returns:
        the mapped applicative

    - #### lazyZip

          public <D> Lazy<Choice3<A,B,D>> lazyZip(Lazy<? extends Applicative<Fn1<? super C,? extends D>,Choice3<A,B,?>>> lazyAppFn)

      Given a `lazy` instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. This is useful for applicatives that support lazy evaluation and early termination.
      Specified by:
        `lazyZip` in interface `Applicative<C,Choice3<A,B,?>>`
      Specified by:
        `lazyZip` in interface `Monad<C,Choice3<A,B,?>>`
      Specified by:
        `lazyZip` in interface `MonadRec<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the resulting applicative parameter type
      Parameters:
        `lazyAppFn` - the lazy other applicative instance
      Returns:
        the mapped applicative
      See Also:
        `Maybe`, `Either`

    - #### discardL

          public <D> Choice3<A,B,D> discardL(Applicative<D,Choice3<A,B,?>> appB)

      Sequence both this `Applicative` and `appB`, discarding this `Applicative's` result and returning `appB`. This is generally useful for sequentially performing side-effects.
      Specified by:
        `discardL` in interface `Applicative<C,Choice3<A,B,?>>`
      Specified by:
        `discardL` in interface `Monad<C,Choice3<A,B,?>>`
      Specified by:
        `discardL` in interface `MonadRec<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the type of the returned Applicative's parameter
      Parameters:
        `appB` - the other Applicative
      Returns:
        appB

    - #### discardR

          public <D> Choice3<A,B,C> discardR(Applicative<D,Choice3<A,B,?>> appB)

      Sequence both this `Applicative` and `appB`, discarding `appB's` result and returning this `Applicative`. This is generally useful for sequentially performing side-effects.
      Specified by:
        `discardR` in interface `Applicative<C,Choice3<A,B,?>>`
      Specified by:
        `discardR` in interface `Monad<C,Choice3<A,B,?>>`
      Specified by:
        `discardR` in interface `MonadRec<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the type of appB's parameter
      Parameters:
        `appB` - the other Applicative
      Returns:
        this Applicative

    - #### flatMap

          public <D> Choice3<A,B,D> flatMap(Fn1<? super C,? extends Monad<D,Choice3<A,B,?>>> f)

      Chain dependent computations that may continue or short-circuit based on previous results.
      Specified by:
        `flatMap` in interface `Monad<C,Choice3<A,B,?>>`
      Specified by:
        `flatMap` in interface `MonadRec<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the resulting monad parameter type
      Parameters:
        `f` - the dependent computation over A
      Returns:
        the new monad instance

    - #### trampolineM

          public <D> Choice3<A,B,D> trampolineM(Fn1<? super C,? extends MonadRec<RecursiveResult<C,D>,Choice3<A,B,?>>> fn)

      Given some operation yielding a `RecursiveResult` inside this `MonadRec`, internally trampoline the operation until it yields a `termination` instruction.

      Stack-safety depends on implementations guaranteeing that the growth of the call stack is a constant factor independent of the number of invocations of the operation. For various examples of how this can be achieved in stereotypical circumstances, see the referenced types.

      Specified by:
        `trampolineM` in interface `MonadRec<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the ultimate resulting carrier type
      Parameters:
        `fn` - the function to internally trampoline
      Returns:
        the trampolined `MonadRec`
      See Also:
        `for a basic implementation`, `for a {@link CoProduct2 coproduct} implementation`, `for an implementation leveraging an already stack-safe {@link Monad#flatMap(Fn1)}`, `for a {@link MonadT monad transformer} implementation`

    - #### traverse

          public <D,App extends Applicative<?,App>,TravB extends Traversable<D,Choice3<A,B,?>>,AppTrav extends Applicative<TravB,App>> AppTrav traverse(Fn1<? super C,? extends Applicative<D,App>> fn,
                                                                                                                                                        Fn1<? super TravB,? extends AppTrav> pure)

      Apply `fn` to each element of this traversable from left to right, and collapse the results into a single resulting applicative, potentially with the assistance of the applicative's pure function.
      Specified by:
        `traverse` in interface `Traversable<C,Choice3<A,B,?>>`
      Type Parameters:
        `D` - the resulting element type
        `App` - the result applicative type
        `TravB` - this Traversable instance over B
        `AppTrav` - the full inferred resulting type from the traversal
      Parameters:
        `fn` - the function to apply
        `pure` - the applicative pure function
      Returns:
        the traversed Traversable, wrapped inside an applicative

    - #### a

          public static <A,B,C> Choice3<A,B,C> a(A a)

      Static factory method for wrapping a value of type `A` in a `Choice3`.
      Type Parameters:
        `A` - the first possible type
        `B` - the second possible type
        `C` - the third possible type
      Parameters:
        `a` - the value
      Returns:
        the wrapped value as a `Choice3`<A, B, C>

    - #### b

          public static <A,B,C> Choice3<A,B,C> b(B b)

      Static factory method for wrapping a value of type `A` in a `Choice3`.
      Type Parameters:
        `A` - the first possible type
        `B` - the second possible type
        `C` - the third possible type
      Parameters:
        `b` - the value
      Returns:
        the wrapped value as a `Choice3`<A, B, C>

    - #### c

          public static <A,B,C> Choice3<A,B,C> c(C c)

      Static factory method for wrapping a value of type `A` in a `Choice3`.
      Type Parameters:
        `A` - the first possible type
        `B` - the second possible type
        `C` - the third possible type
      Parameters:
        `c` - the value
      Returns:
        the wrapped value as a `Choice3`<A, B, C>

    - #### pureChoice

          public static <A,B> Pure<Choice3<A,B,?>> pureChoice()

      The canonical `Pure` instance for `Choice3`.
      Type Parameters:
        `A` - the first possible type
        `B` - the second possible type
      Returns:
        the `Pure` instance