dnowak
12/22/2021, 5:04 PMraulraja
12/22/2021, 9:57 PMUnit
.public fun divide(num: Int, den: Int): Int =
num / den
public data class User(val id: Int, val name: String)
public fun createUser(name: String, id: Int): User =
User(id, name)
public fun main() {
val halfOf = Partial(::divide).second(2)
val ten: Int = halfOf(20)
val createUserJaneWithId = Partial(::createUser).first("Jane")
val jane = createUserJaneWithId(ten)
println(jane) //User(id=10, name=Jane)
}
Partial(::divide).second(2) //applies the second arg
val createUserJaneWithId = Partial(::createUser).first("Jane") // applies the first arg
Partial
is a fun interface
it is also a function that can be invokedpublic operator fun invoke(a: A, b: B): Partial<Unit, Unit, C, D, Z> =
Partial { _, _, c, d -> invoke(a, b, c, d) }
dnowak
12/23/2021, 10:38 AMcurried
or chain of partially1
creates a bunch of functions.raulraja
12/23/2021, 10:55 AMdnowak
12/23/2021, 2:01 PMraulraja
12/23/2021, 2:07 PMdnowak
12/23/2021, 2:11 PM