Class Tagged<S,B>

java.lang.Object
com.jnape.palatable.lambda.functor.builtin.Tagged<S,B>
Type Parameters:
S - the phantom type
B - the value type
All Implemented Interfaces:
Applicative<B, Tagged<S,?>>, Cocartesian<S, B, Tagged<?,?>>, Contravariant<S, Profunctor<?, B, Tagged<?,?>>>, Functor<B, Tagged<S,?>>, Profunctor<S, B, Tagged<?,?>>, Monad<B, Tagged<S,?>>, MonadRec<B, Tagged<S,?>>, Traversable<B, Tagged<S,?>>

public final class Tagged<S,B> extends Object implements MonadRec<B, Tagged<S,?>>, Traversable<B, Tagged<S,?>>, Cocartesian<S, B, Tagged<?,?>>
Like Const, but the phantom parameter is in the contravariant position, and the value is in covariant position.
  • Field Details

    • b

      private final B b
  • Constructor Details

    • Tagged

      public Tagged(B b)
  • Method Details

    • unTagged

      public B unTagged()
      Extract the contained value.
      Returns:
      the value
    • flatMap

      public <C> Tagged<S,C> flatMap(Fn1<? super B, ? extends Monad<C, Tagged<S,?>>> f)
      Chain dependent computations that may continue or short-circuit based on previous results.
      Specified by:
      flatMap in interface Monad<S,B>
      Specified by:
      flatMap in interface MonadRec<S,B>
      Type Parameters:
      C - the resulting monad parameter type
      Parameters:
      f - the dependent computation over A
      Returns:
      the new monad instance
    • trampolineM

      public <C> Tagged<S,C> trampolineM(Fn1<? super B, ? extends MonadRec<RecursiveResult<B,C>, Tagged<S,?>>> 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<S,B>
      Type Parameters:
      C - the ultimate resulting carrier type
      Parameters:
      fn - the function to internally trampoline
      Returns:
      the trampolined MonadRec
      See Also:
    • pure

      public <C> Tagged<S,C> pure(C c)
      Lift the value b into this applicative functor.
      Specified by:
      pure in interface Applicative<S,B>
      Specified by:
      pure in interface Monad<S,B>
      Specified by:
      pure in interface MonadRec<S,B>
      Type Parameters:
      C - the type of the returned applicative's parameter
      Parameters:
      c - the value
      Returns:
      an instance of this applicative over b
    • fmap

      public <C> Tagged<S,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<S,B>
      Specified by:
      fmap in interface Functor<S,B>
      Specified by:
      fmap in interface Monad<S,B>
      Specified by:
      fmap in interface MonadRec<S,B>
      Specified by:
      fmap in interface Traversable<S,B>
      Type Parameters:
      C - the new parameter type
      Parameters:
      fn - the mapping function
      Returns:
      a functor over B (the new parameter type)
    • zip

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

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

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

      public <C, App extends Applicative<?,App>, TravC extends Traversable<C, Tagged<S,?>>, 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<S,B>
      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
    • cocartesian

      public <C> Tagged<Choice2<C,S>, Choice2<C,B>> cocartesian()
      Choose some type C or this profunctor's carrier types.
      Specified by:
      cocartesian in interface Cocartesian<S, B, Tagged<?,?>>
      Type Parameters:
      C - the choice type
      Returns:
      the cocartesian-costrengthened profunctor
    • diMap

      public <Z,C> Tagged<Z,C> diMap(Fn1<? super Z, ? extends S> lFn, Fn1<? super B, ? extends C> rFn)
      Dually map contravariantly over the left parameter and covariantly over the right parameter. This is isomorphic to diMapL(lFn).diMapR(rFn).
      Specified by:
      diMap in interface Cocartesian<S, B, Tagged<?,?>>
      Specified by:
      diMap in interface Profunctor<S, B, Tagged<?,?>>
      Type Parameters:
      Z - the new left parameter type
      C - the new right parameter type
      Parameters:
      lFn - the left parameter mapping function
      rFn - the right parameter mapping function
      Returns:
      a profunctor over Z (the new left parameter type) and C (the new right parameter type)
    • diMapL

      public <Z> Tagged<Z,B> diMapL(Fn1<? super Z, ? extends S> fn)
      Contravariantly map over the left parameter.
      Specified by:
      diMapL in interface Cocartesian<S, B, Tagged<?,?>>
      Specified by:
      diMapL in interface Profunctor<S, B, Tagged<?,?>>
      Type Parameters:
      Z - the new left parameter type
      Parameters:
      fn - the mapping function
      Returns:
      a profunctor over Z (the new left parameter type) and C (the same right parameter type)
    • diMapR

      public <C> Tagged<S,C> diMapR(Fn1<? super B, ? extends C> fn)
      Covariantly map over the right parameter. For all profunctors that are also functors, it should hold that diMapR(f) == fmap(f).
      Specified by:
      diMapR in interface Cocartesian<S, B, Tagged<?,?>>
      Specified by:
      diMapR in interface Profunctor<S, B, Tagged<?,?>>
      Type Parameters:
      C - the new right parameter type
      Parameters:
      fn - the mapping function
      Returns:
      a profunctor over A (the same left parameter type) and C (the new right parameter type)
    • contraMap

      public <Z> Tagged<Z,B> contraMap(Fn1<? super Z, ? extends S> fn)
      Contravariantly map A <- B.
      Specified by:
      contraMap in interface Cocartesian<S, B, Tagged<?,?>>
      Specified by:
      contraMap in interface Contravariant<S,B>
      Specified by:
      contraMap in interface Profunctor<S, B, Tagged<?,?>>
      Type Parameters:
      Z - the new parameter type
      Parameters:
      fn - the mapping function
      Returns:
      the mapped Contravariant functor instance
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • pureTagged

      public static <S> Pure<Tagged<S,?>> pureTagged()
      The canonical Pure instance for Tagged.
      Type Parameters:
      S - the phantom type
      Returns:
      the Pure instance