Skip to content

Instantly share code, notes, and snippets.

View ayoub-benali's full-sized avatar

Ayoub Benali ayoub-benali

View GitHub Profile
@ayoub-benali
ayoub-benali / ErrorFailure.scala
Created April 5, 2016 14:45 — forked from atamborrino/ErrorFailure.scala
Monad transformer for Future[A Or Every[Error]]
package models.error
import org.scalactic._
import scala.concurrent.{ExecutionContext, Future}
import org.scalactic.Accumulation._
trait Error
object FutureOr {
type Errors = Every[Error]
import scala.util.Try
// isn't the following line supposed not to compile ?
val foo: Try[Unit] = Try{1+1}.map{x => Try{x/0}}
// foo: scala.util.Try[Unit] = Success(())
val foo: Try[Unit] = Try{1+1}.flatMap{x => Try{x/0}}
// scala.util.Try[Unit] = Failure(java.lang.ArithmeticException: / by zero)