Hacker News new | ask | show | jobs
by throwawuy222 4079 days ago
For those who don't understand: Scalaz is an additional layer of syntax and tricks on top of what is already there. It seems to have quite a lot of power!

    implicit val option = new Traverse[Option] with MonadPlus[Option] {
    def point[A](a: => A) = Some(a)
    def bind[A, B](fa: Option[A])(f: A => Option[B]): Option[B] = fa flatMap f
    override def map[A, B](fa: Option[A])(f: A => B): Option[B] = fa map f
    def traverseImpl[F[_], A, B](fa: Option[A])(f: A => F[B])(implicit F: Applicative[F]) =
      fa map (a => F.map(f(a))(Some(_): Option[B])) getOrElse F.point(None)
    def empty[A]: Option[A] = None
    def plus[A](a: Option[A], b: => Option[A]) = a orElse b
    def foldR[A, B](fa: Option[A], z: B)(f: (A) => (=> B) => B): B = fa match {
      case Some(a) => f(a)(z)
      case None => z
    }
  }
Excerpt from https://github.com/scalaz/scalaz#type-class-instance-definit....
1 comments

Looks pretty readable and reasonable.
That part is fine. The trouble with Scalaz is it adds a bunch of extra operators (that is, methods - the distinction doesn't exist in Scala) like |+|, \*> and >=>.