Created
July 3, 2018 17:15
-
-
Save danslapman/038c1afcfa8ca3a85b8a018b400b1e8f to your computer and use it in GitHub Desktop.
Function combination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interp.configureCompiler(_.settings.YpartialUnification.value = true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $file.`conf` | |
import $ivy.`org.typelevel::cats-core:1.1.0` | |
import cats.{Endo, Semigroup, SemigroupK} | |
import cats.instances.function._ | |
import cats.instances.option._ | |
import cats.syntax.semigroup._ | |
import cats.syntax.semigroupk._ | |
implicit def endoSemigroup[T]: Semigroup[Endo[T]] = new Semigroup[Endo[T]] { | |
override def combine(x: Endo[T], y: Endo[T]) = x andThen y | |
} | |
val f1: Option[Int => Int] = Some(_ + 1) | |
val f2: Option[Int => Int] = Some(_ + 2) | |
val f3: Option[Int => Int] = None | |
val fx = (f3 |+| f3).getOrElse(identity[Int](_)) | |
println(fx(0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment