Commit d04af372 authored by Florian Strunz's avatar Florian Strunz
Browse files

[10] Replace illegal states with misc templates

parent 3e4b2ccc
......@@ -18,7 +18,7 @@ usually marked with `???`.
| 7: Applicative Functors | [`fp07`](src/main/scala/fp07) |
| 8: State (and some Applicative) | [`fp08`](src/main/scala/fp08) |
| 9: Traversable Functors | [`fp09`](src/main/scala/fp09) |
| 10: Illegal States | [`fp10`](src/main/scala/fp10) |
| 10: Miscellaneous | [`fp10`](src/main/scala/fp10) |
| 11: Parser Combinators | [`fp11`](src/main/scala/fp11) |
## Usage tips:
......
package fp10
import cats._
import cats.implicits._
import scala.language.higherKinds
import cats.Traverse
import cats.data.State.{get, set}
object FP10 {
// Aufgabe 5: Monad Laws
def semigroupKForMonads[F[_]:Monad]: SemigroupK[F] = ???
def main(args: Array[String]): Unit = {
val x: List[String] = List("A", "B", "C")
val y: List[String] = List("B", "a", "u", "m")
val z: List[String] = List("Serotonin")
val F = semigroupKForMonads[List]
println(F.combineK(x, y))
println(F.combineK(F.combineK(x, y), z) == F.combineK(x, F.combineK(y, z)))
}
def mapAccum[F[_]:Traverse,S,A,B](fa: F[A], s: S)(f: (A, S) => (B, S)): (F[B], S) =
Traverse[F].traverse(fa)((a: A) => for {
s1 <- get[S]
(b, s2) = f(a, s1)
_ <- set(s2)
} yield b).run(s).value.swap
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment