Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mandubian
Created November 12, 2017 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandubian/3eb1552b984a0fec7cde22a5e744857e to your computer and use it in GitHub Desktop.
Save mandubian/3eb1552b984a0fec7cde22a5e744857e to your computer and use it in GitHub Desktop.
implicit val Function1ClosedCartesianCat: ClosedCartesianCat[Function1] = new ClosedCartesianCat[Function1] {
def id[A]: A => A = identity
def ○[A, B, C]: (B => C) => (A => B) => (A => C) = f => g => f compose g
def ⨂[A, C, D]: (A => C) => (A => D) => (A => (C, D)) = f => g => (a => (f(a), g(a)))
def exl[A, B]: ((A, B)) => A = _._1
def exr[A, B]: ((A, B)) => B = _._2
def it[A]: A => Unit = _ => ()
def ap[A, B]: ((A => B, A)) => B = f => f._1(f._2)
def curry[A, B, C]: (((A, B)) => C) => (A => (B => C)) = f => a => (b => f((a, b)))
def uncurry[A, B, C]: (A => (B => C)) => (((A, B)) => C) = f => { case (a, b) => f(a)(b) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment