Skip to content

Instantly share code, notes, and snippets.

@rupeshtr78
Created November 5, 2020 21:16
Show Gist options
  • Save rupeshtr78/aba1b58c2dee3ab12aa3dfcc582307c9 to your computer and use it in GitHub Desktop.
Save rupeshtr78/aba1b58c2dee3ab12aa3dfcc582307c9 to your computer and use it in GitHub Desktop.
package MoniodsFunctorMonad
object MonadBasic {
trait Functor[T] {
def map[Y](f: T => Y): Functor[Y]
}
trait Monad[T] extends Functor[T] {
def unit[Y](value: Y): Monad[Y]
def flatMap[Y](f: T => Monad[Y]): Monad[Y]
override def map[Y](f: T => Y): Monad[Y] =
flatMap(i => unit(f(i)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment