Commit cae1be27 authored by Tim Hegemann's avatar Tim Hegemann
Browse files

Add task sheet 5: Typeclasses, Functors, and Cats

parent 1f5c3f23
......@@ -8,11 +8,12 @@ Templates are within `src/main/scala`. Parts that you should complete are
usually marked with `???`.
| task sheet | package |
|---------------------------------|-------------------------------------------------------------------|
|------------------------------------|-------------------------------------------------------------------|
| 1: Functional Data Structures | \<no templates\> |
| 2: Error Handling | [`fp02`](src/main/scala/fp02) |
| 3: Strictness and Laziness | [`fp03`](src/main/scala/fp03) |
| 4: Laws, Monoids, and Foldable | [`fp04`](src/main/scala/fp04) |
| 5: Typeclasses, Functors, and Cats | [`fp05`](src/main/scala/fp05) |
## Usage tips:
To keep your local solutions to the exercises when pulling from the repository,
......
......@@ -44,4 +44,5 @@ scalacOptions ++= Seq(
)
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.5"
libraryDependencies += "org.typelevel" % "cats-core_2.12" % "2.0.0-M3"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
package fp05
import cats.Monoid
import cats.instances.int._
import cats.syntax.monoid._
object InvariantMonoid {
def imap[A: Monoid,B](f: A => B, g: B => A): Monoid[B] = ???
case class Box[+A](value: A)
implicit def boxMonoid[A: Monoid]: Monoid[Box[A]] = ???
def main(args: Array[String]): Unit = {
// if this one does not compile you messed up your implicits
implicitly[Monoid[Box[Int]]]
println(Box(7) |+| Box(12))
}
}
package fp05
import cats.{Eval, Foldable, Functor, SemigroupK}
import cats.syntax.all._
sealed trait Tree[+A]
final case class Branch[A](left: Tree[A], right: Tree[A]) extends Tree[A]
final case class Leaf[A](value: A) extends Tree[A]
object TreeInstances {
implicit val semigroup: SemigroupK[Tree] = ???
implicit val functor: Functor[Tree] = ???
implicit val foldable: Foldable[Tree] = ???
}
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