Created
January 3, 2017 19:54
-
-
Save anonymous/5548ee6fb4aabb9b67aa37c0a0985cdc to your computer and use it in GitHub Desktop.
Scala Kata shared content
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 com.scalakata._ | |
@instrument class Playground { | |
// help | |
def partial1[A, B, C](a: A, f: (A, B) => C): B => C = | |
b => f(a, b) | |
def curry[A, B, C](f: (A, B) => C): A => B => C = | |
a => b => f(a, b) | |
def uncurry[A, B, C](f: A => B => C): (A, B) => C = | |
(a, b) => f(a)(b) | |
def compose[A, B, C](f: B => C, g: A => B): A => C = | |
(a) => f(g(a)) | |
def sum(a: Int, b: Int): Int = a + b | |
val curriedSum = curry(sum) | |
curriedSum(1)(2) | |
val uncurriedSum = uncurry(curriedSum) | |
uncurriedSum(1, 2) | |
def intToFloat(i: Int): Float = i.toFloat | |
def floatToString(f: Float): String = f.toString | |
val intAsFloatToString = compose(floatToString, intToFloat) | |
intAsFloatToString(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment