Skip to content

Commit

Permalink
Merge pull request #1472 from denisftw/freeapp-tutorial-regular-syntax
Browse files Browse the repository at this point in the history
Using regular syntax in the FreeApplicative tutorial (#1471)
  • Loading branch information
ceedubs authored May 13, 2017
2 parents 5340ee6 + 50e0a2c commit 6bb1ca1
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions docs/src/main/tut/datatypes/freeapplicative.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ import cats.implicits._
// a function that takes a string as input
type FromString[A] = String => A
val compiler =
λ[FunctionK[ValidationOp, FromString]] { fa =>
str =>
fa match {
case Size(size) => str.size >= size
case HasNumber => str.exists(c => "0123456789".contains(c))
}
}
val compiler = new FunctionK[ValidationOp, FromString] {
def apply[A](fa: ValidationOp[A]): FromString[A] = str =>
fa match {
case Size(size) => str.size >= size
case HasNumber => str.exists(c => "0123456789".contains(c))
}
}
```

```tut:book
Expand Down Expand Up @@ -101,15 +100,14 @@ import scala.concurrent.ExecutionContext.Implicits.global
// recall Kleisli[Future, String, A] is the same as String => Future[A]
type ParValidator[A] = Kleisli[Future, String, A]
val parCompiler =
λ[FunctionK[ValidationOp, ParValidator]] { fa =>
Kleisli { str =>
fa match {
case Size(size) => Future { str.size >= size }
case HasNumber => Future { str.exists(c => "0123456789".contains(c)) }
}
val parCompiler = new FunctionK[ValidationOp, ParValidator] {
def apply[A](fa: ValidationOp[A]): ParValidator[A] = Kleisli { str =>
fa match {
case Size(size) => Future { str.size >= size }
case HasNumber => Future { str.exists(c => "0123456789".contains(c)) }
}
}
}
val parValidator = prog.foldMap[ParValidator](parCompiler)
```
Expand All @@ -127,11 +125,12 @@ import cats.implicits._
type Log[A] = Const[List[String], A]
val logCompiler =
λ[FunctionK[ValidationOp, Log]] {
val logCompiler = new FunctionK[ValidationOp, Log] {
def apply[A](fa: ValidationOp[A]): Log[A] = fa match {
case Size(size) => Const(List(s"size >= $size"))
case HasNumber => Const(List("has number"))
case HasNumber => Const(List("has number"))
}
}
def logValidation[A](validation: Validation[A]): List[String] =
validation.foldMap[Log](logCompiler).getConst
Expand Down

0 comments on commit 6bb1ca1

Please sign in to comment.