Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sometimes I missed .uncurried cuntionality in Scala
trait Uncurry[C, U] {
def uncurried(curried: C): U
}
object Uncurry {
def instance[C, U](body: C => U) = new Uncurry[C, U] {
def uncurried(curried: C): U = body(curried)
}
implicit def uncurry2[A, B, Out]: Uncurry[A => B => Out, (A, B) => Out] =
instance[A => B => Out, (A, B) => Out] { curried => curried(_)(_) }
implicit def uncurry3[A, B, C, Out]: Uncurry[A => B => C => Out, (A, B, C) => Out] =
instance[A => B => C => Out, (A, B, C) => Out] { curried => curried(_)(_)(_) }
implicit def uncurry4[A, B, C, D, Out]: Uncurry[A => B => C => D => Out, (A, B, C, D) => Out] =
instance[A => B => C => D => Out, (A, B, C, D) => Out] { curried => curried(_)(_)(_)(_) }
implicit def uncurry5[A, B, C, D, E, Out]: Uncurry[A => B => C => D => E => Out, (A, B, C, D, E) => Out] =
instance[A => B => C => D => E => Out, (A, B, C, D, E) => Out] { curried => curried(_)(_)(_)(_)(_) }
}
implicit class UncurryOps[C, U](curried: C)(implicit uncurry: Uncurry[C, U]) {
def uncurried: U = uncurry.uncurried(curried)
}
((i: Int, j: Int) => i.toString + j.toString).curried.uncurried
@MateuszKubuszok

This comment has been minimized.

Copy link
Owner Author

@MateuszKubuszok MateuszKubuszok commented Mar 14, 2020

Alternative to Function.uncurried

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment