Package

sclib

z

Permalink

package z

functor, monad, monad-transformer

- for zero runtime dependencies of this library, some concepts are reimplemented here - very basic / minimal Functor and Monad implementations

check the member documentation for examples

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. z
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. case class EitherT[F[_], A, B](runEitherT: F[Either[A, B]]) extends Product with Serializable

    Permalink

    minimalistic Either monad transformer

    minimalistic Either monad transformer

    Example:
    1. scala> import sclib.z._
      scala> import sclib.ops.either._
      scala> val et = EitherT[Function1[Int, ?], String, Int]{i => if(i < 10) i.right else "BOOM".left}
      et: sclib.z.EitherT[[A]Int => A,String,Int] = EitherT(<function1>)
      scala> et.runEitherT(5)
      res0: Either[String,Int] = Right(5)
      scala> et.runEitherT(50)
      res1: Either[String,Int] = Left(BOOM)
  2. trait Functor[F[_]] extends AnyRef

    Permalink

    minimalistic Functor

  3. case class ListT[F[_], A](runListT: F[List[A]]) extends Product with Serializable

    Permalink

    minimalistic List monad transformer

    minimalistic List monad transformer

    Example:
    1. scala> import sclib.z._
      scala> import sclib.ops.`try`._
      scala> (for {
           |   a <- ListT(List(1, 2).success)
           |   b <- ListT(List(3, 4).success)
           | } yield a + b).runListT
      res0: scala.util.Try[List[Int]] = Success(List(4, 5, 5, 6))
      scala> (for {
           |   a <- ListT(List(1, 2).success)
           |   b <- ListT("BOOM".failure[List[Int]])
           | } yield a + b).runListT
      res1: scala.util.Try[List[Int]] = Failure(java.lang.Exception: BOOM)
  4. trait Monad[F[_]] extends Functor[F]

    Permalink

    minimalistic Monad

  5. case class Reader[C, A](runReader: (C) ⇒ A) extends Product with Serializable

    Permalink

    minimalistic Reader monad

    minimalistic Reader monad

    Example:
    1. scala> import sclib.z._
      scala> val action = for {
           |   a <- Reader[Int, Int]{_ + 5}
           |   b <- Reader[Int, Int]{_ + 10}
           | } yield (a, b)
      action: sclib.z.Reader[Int,(Int, Int)] = Reader(<function1>)
      scala> action.runReader(1)
      res0: (Int, Int) = (6,11)
  6. case class State[S, A](run: (S) ⇒ (A, S)) extends Product with Serializable

    Permalink

    minimalistic State monad

    minimalistic State monad

    Example:
    1. scala> import sclib.z._
      scala> val action = for {
           |   a <- State[Int, Int](i => (i, i + 1))
           |   b <- State[Int, Int](i => (i, i + 1))
           | } yield a -> b
      action: sclib.z.State[Int,(Int, Int)] = State(<function1>)
      scala> action.run(0)
      res1: ((Int, Int), Int) = ((0,1),2)
  7. case class StateT[F[_], S, A](runStateT: F[(S) ⇒ F[(A, S)]]) extends Product with Serializable

    Permalink

    minimalistic State monad transformer

    minimalistic State monad transformer

    Example:
    1. scala> import sclib.z._
      scala> import sclib.ops.`try`._
      scala> import scala.util.Try
      scala> val pf = StateT{i: Int => if(i < 10) (i, i + 1).success else "BOOM".failure}
      scala> val action = for {
           |   a <- pf
           |   b <- pf
           | } yield a -> b
      scala> action.run(0)
      res1: scala.util.Try[((Int, Int), Int)] = Success(((0,1),2))
      scala> action.run(10)
      res2: scala.util.Try[((Int, Int), Int)] = Failure(java.lang.Exception: BOOM)
  8. case class TryT[F[_], A](runTryT: F[Try[A]]) extends Product with Serializable

    Permalink

    minimalistic Try monad transformer

    minimalistic Try monad transformer

    Example:
    1. scala> import sclib.z._
      scala> import sclib.ops.`try`._
      scala> val tt = TryT[Function1[Int, ?], Int]{i => if(i < 10) i.success else "BOOM".failure}
      scala> tt.map(_ * 10).runTryT(5)
      res0: scala.util.Try[Int] = Success(50)
      scala> tt.map(_ * 10).runTryT(10)
      res1: scala.util.Try[Int] = Failure(java.lang.Exception: BOOM)

Value Members

  1. object ListT extends Serializable

    Permalink
  2. object StateT extends Serializable

    Permalink
  3. implicit def eitherInstance[A]: Functor[[β]Either[A, β]] with Monad[[β]Either[A, β]]

    Permalink

    Eithers Functor and Monad instances

  4. implicit def function0Instances: Functor[Function0] with Monad[Function0]

    Permalink

    Function0s Functor and Monad instances

  5. implicit def function1Instances[A]: Functor[[β](A) ⇒ β] with Monad[[β](A) ⇒ β]

    Permalink

    Function1s Functor and Monad instances

  6. implicit def iteratorInstances: Functor[Iterator] with Monad[Iterator]

    Permalink

    Iterators Functor and Monad instances

  7. implicit def listInstances: Functor[List] with Monad[List]

    Permalink

    Lists Functor and Monad instances

  8. implicit def optionInstances: Functor[Option] with Monad[Option]

    Permalink

    Options Functor and Monad instances

  9. implicit def readerInstances[C]: Functor[[β]Reader[C, β]] with Monad[[β]Reader[C, β]]

    Permalink

    Readers Functor and Monad instances

  10. implicit def setInstances: Functor[Set] with Monad[Set]

    Permalink

    Sets Functor and Monad instances

  11. implicit def stateInstances[S]: Functor[[β]State[S, β]] with Monad[[β]State[S, β]]

    Permalink

    States Functor and Monad instances

  12. implicit def tryInstance: Functor[Try] with Monad[Try]

    Permalink

    Trys Functor and Monad instances

  13. implicit def vectorInstances: Functor[Vector] with Monad[Vector]

    Permalink

    Vectors Functor and Monad instances

Inherited from AnyRef

Inherited from Any

Ungrouped