Skip to content

Commit

Permalink
Inspired by haskell/mtl#5
Browse files Browse the repository at this point in the history
This commit closes scalaz#1658
  • Loading branch information
Dmitry Ivanov committed Aug 2, 2018
1 parent 233dc67 commit fd2a66f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/src/main/scala/scalaz/MonadReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ trait MonadReader[F[_], S] extends Monad[F] { self =>

////

trait MonadReaderLaw extends MonadLaw {
def localPoint[A](f: S => S)(a: A)(implicit FA: Equal[F[A]]): Boolean =
FA.equal(local(f)(point(a)), point(a))

def localComposition[A](f: S => S, g: S => S)(fa: F[A])(implicit FA: Equal[F[A]]): Boolean =
FA.equal(local(f)(local(g)(fa)), local(f andThen g)(fa))

def localFAsk(f: S => S)(implicit FS: Equal[F[S]]): Boolean =
FS.equal(local(f)(ask), map(ask)(f))

def askIdempotence(implicit FS: Equal[F[S]]): Boolean =
FS.equal(ask, apply2(ask, ask)((_, b) => b))

def askFALeft[A](fa: F[A])(implicit FA: Equal[F[A]]): Boolean =
FA.equal(apply2(ask, fa)((_, b) => b), fa)

def askFARight[A](fa: F[A])(implicit FA: Equal[F[A]]): Boolean =
FA.equal(apply2(fa, ask)((a, _) => a), fa)
}

def monadReaderLaw = new MonadReaderLaw {}
}

object MonadReader {
Expand Down

0 comments on commit fd2a66f

Please sign in to comment.