Skip to content

Instantly share code, notes, and snippets.

@danslapman
Created July 3, 2018 17:15
Show Gist options
  • Save danslapman/038c1afcfa8ca3a85b8a018b400b1e8f to your computer and use it in GitHub Desktop.
Save danslapman/038c1afcfa8ca3a85b8a018b400b1e8f to your computer and use it in GitHub Desktop.
Function combination
interp.configureCompiler(_.settings.YpartialUnification.value = true)
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