com.jnape.palatable.lambda.adt

## Class These<A,B>

- java.lang.Object
- - com.jnape.palatable.lambda.adt.These<A,B>

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

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

  The coproduct of a coproduct (``CoProduct2`<A, B>`) and its product (``Tuple2`<A, B>`), represented as a ``CoProduct3`<A, B, `Tuple2`<A, B>>`.

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <A,B> These<A,B>` | `a(A a)` Static factory method for wrapping a value of type `A` in a `These`.
    `static <A,B> These<A,B>` | `b(B b)` Static factory method for wrapping a value of type `B` in a `These`.
    `<C,D> These<C,D>` | `biMap(Fn1<? super A,? extends C> lFn, Fn1<? super B,? extends D> rFn)` Dually map covariantly over both the left and right parameters.
    `<Z> These<Z,B>` | `biMapL(Fn1<? super A,? extends Z> fn)` Covariantly map over the left parameter.
    `<C> These<A,C>` | `biMapR(Fn1<? super B,? extends C> fn)` Covariantly map over the right parameter.
    `static <A,B> These<A,B>` | `both(A a, B b)` Static factory method for wrapping a value of type `A` and a value of type `B` in a `These`.
    `<C> These<A,C>` | `discardL(Applicative<C,These<A,?>> appB)` Sequence both this `Applicative` and `appB`, discarding this `Applicative's` result and returning `appB`.
    `<C> These<A,B>` | `discardR(Applicative<C,These<A,?>> appB)` Sequence both this `Applicative` and `appB`, discarding `appB's` result and returning this `Applicative`.
    `<C> These<A,C>` | `flatMap(Fn1<? super B,? extends Monad<C,These<A,?>>> f)` Chain dependent computations that may continue or short-circuit based on previous results.
    `<C> These<A,C>` | `fmap(Fn1<? super B,? extends C> fn)` Covariantly transmute this functor's parameter using the given mapping function.
    `<C> Lazy<These<A,C>>` | `lazyZip(Lazy<? extends Applicative<Fn1<? super B,? extends C>,These<A,?>>> 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.
    `<C> These<A,C>` | `pure(C c)` Lift the value `b` into this applicative functor.
    `static <A> Pure<These<A,?>>` | `pureThese()` The canonical `Pure` instance for `These`.
    `<C> These<A,C>` | `trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,These<A,?>>> fn)` Given some operation yielding a `RecursiveResult` inside this `MonadRec`, internally trampoline the operation until it yields a `termination` instruction.
    `<C,App extends Applicative<?,App>,TravC extends Traversable<C,These<A,?>>,AppTrav extends Applicative<TravC,App>> AppTrav` | `traverse(Fn1<? super B,? extends Applicative<C,App>> fn, Fn1<? super TravC,? 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.
    `<C> These<A,C>` | `zip(Applicative<Fn1<? super B,? extends C>,These<A,?>> 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

      `converge, diverge, embed, match, project, 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

    - #### biMap

          public final <C,D> These<C,D> biMap(Fn1<? super A,? extends C> lFn,
                                              Fn1<? super B,? extends D> 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<A,B,These<?,?>>`
      Specified by:
        `biMap` in interface `BoundedBifunctor<A,B,Object,Object,These<?,?>>`
      Type Parameters:
        `C` - the new left parameter type
        `D` - 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)

    - #### flatMap

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

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

    - #### trampolineM

          public <C> These<A,C> trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,These<A,?>>> 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<B,These<A,?>>`
      Type Parameters:
        `C` - 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`

    - #### pure

          public final <C> These<A,C> pure(C c)

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

    - #### traverse

          public <C,App extends Applicative<?,App>,TravC extends Traversable<C,These<A,?>>,AppTrav extends Applicative<TravC,App>> AppTrav traverse(Fn1<? super B,? extends Applicative<C,App>> fn,
                                                                                                                                                    Fn1<? super TravC,? 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<B,These<A,?>>`
      Type Parameters:
        `C` - the resulting element type
        `App` - the result applicative type
        `TravC` - 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

    - #### biMapL

          public final <Z> These<Z,B> biMapL(Fn1<? super A,? extends Z> fn)

      Covariantly map over the left parameter.
      Specified by:
        `biMapL` in interface `Bifunctor<A,B,These<?,?>>`
      Specified by:
        `biMapL` in interface `BoundedBifunctor<A,B,Object,Object,These<?,?>>`
      Type Parameters:
        `Z` - 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 <C> These<A,C> biMapR(Fn1<? super B,? extends C> 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<A,B,These<?,?>>`
      Specified by:
        `biMapR` in interface `BoundedBifunctor<A,B,Object,Object,These<?,?>>`
      Type Parameters:
        `C` - 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)

    - #### fmap

          public final <C> These<A,C> fmap(Fn1<? super B,? extends C> 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<B,These<A,?>>`
      Specified by:
        `fmap` in interface `Functor<B,These<A,?>>`
      Specified by:
        `fmap` in interface `Monad<B,These<A,?>>`
      Specified by:
        `fmap` in interface `MonadRec<B,These<A,?>>`
      Specified by:
        `fmap` in interface `Traversable<B,These<A,?>>`
      Type Parameters:
        `C` - the new parameter type
      Parameters:
        `fn` - the mapping function
      Returns:
        a functor over B (the new parameter type)

    - #### zip

          public final <C> These<A,C> zip(Applicative<Fn1<? super B,? extends C>,These<A,?>> 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<B,These<A,?>>`
      Specified by:
        `zip` in interface `Monad<B,These<A,?>>`
      Specified by:
        `zip` in interface `MonadRec<B,These<A,?>>`
      Type Parameters:
        `C` - the resulting applicative parameter type
      Parameters:
        `appFn` - the other applicative instance
      Returns:
        the mapped applicative

    - #### lazyZip

          public <C> Lazy<These<A,C>> lazyZip(Lazy<? extends Applicative<Fn1<? super B,? extends C>,These<A,?>>> 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<B,These<A,?>>`
      Specified by:
        `lazyZip` in interface `Monad<B,These<A,?>>`
      Specified by:
        `lazyZip` in interface `MonadRec<B,These<A,?>>`
      Type Parameters:
        `C` - the resulting applicative parameter type
      Parameters:
        `lazyAppFn` - the lazy other applicative instance
      Returns:
        the mapped applicative
      See Also:
        `Maybe`, `Either`

    - #### discardL

          public final <C> These<A,C> discardL(Applicative<C,These<A,?>> 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<B,These<A,?>>`
      Specified by:
        `discardL` in interface `Monad<B,These<A,?>>`
      Specified by:
        `discardL` in interface `MonadRec<B,These<A,?>>`
      Type Parameters:
        `C` - the type of the returned Applicative's parameter
      Parameters:
        `appB` - the other Applicative
      Returns:
        appB

    - #### discardR

          public final <C> These<A,B> discardR(Applicative<C,These<A,?>> 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<B,These<A,?>>`
      Specified by:
        `discardR` in interface `Monad<B,These<A,?>>`
      Specified by:
        `discardR` in interface `MonadRec<B,These<A,?>>`
      Type Parameters:
        `C` - the type of appB's parameter
      Parameters:
        `appB` - the other Applicative
      Returns:
        this Applicative

    - #### a

          public static <A,B> These<A,B> a(A a)

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

    - #### b

          public static <A,B> These<A,B> b(B b)

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

    - #### both

          public static <A,B> These<A,B> both(A a,
                                              B b)

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

    - #### pureThese

          public static <A> Pure<These<A,?>> pureThese()

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