I See Voices
I See Voices

Reputation: 852

bind syntax in scalaz

Is there a way to use nice haskell-bind (>>) syntax in scalaz, to write the code that way: monad1 >> monad2?

ToBindOps requires explicit monad to be passed, so I have to do something like ToBindOps[F, Unit](monad1) >> monad2 in oder to get access to >>, which is already an overkill, because monad1 >>= (_ => monad2) is simpler.

( In my particular case monad1 is Free[A, B], so I have a >>= "for free", but the need for bind pops up quite often for other monads as well)

Upvotes: 1

Views: 144

Answers (1)

ZhekaKozlov
ZhekaKozlov

Reputation: 39654

Yes, you can do it by importing an object scalaz.syntax.monad (or scalaz.syntax.bind). This will bring an implicit instance of BindOps to the scope:

import scalaz.effect.IO
import scalaz.syntax.monad._

IO.putStrLn("Hello!") >> IO.putStrLn("How are you?")

Upvotes: 2

Related Questions