https://kotlinlang.org logo
Title
r

Rob Elliot

03/30/2022, 10:09 AM
Just recently (in an answer in #getting-started) I found myself writing these functions:
fun <A, B,    R> ((A, B   ) -> R).curry(a: A): (B   ) -> R = { b: B       -> this(a, b   ) }
fun <A, B, C, R> ((A, B, C) -> R).curry(a: A): (B, C) -> R = { b: B, c: C -> this(a, b, c) }
Do they already exist in the stdlib? Or are they a bit too Haskelly for Kotlin?
k

Klitos Kyriacou

03/30/2022, 10:20 AM
I can't find anything similar in the stdlib; maybe they exist under some name. I don't think they're too Haskelly; the C++ Standard Library has such a function (named
bind
instead of
curry
) - see e.g. https://stackoverflow.com/a/6610165/13963086
👍 1
m

marstran

03/30/2022, 10:59 AM
r

Rob Elliot

03/30/2022, 11:00 AM
Yes, I'm sure there must be loads of functional libs providing this, it's such an obvious and easy thing to write - and consequently felt like something I might expect to see in the stdlib.
e

ephemient

03/30/2022, 9:27 PM
Kotlin's type inference doesn't work on lambdas in receiver position so even if it were a common pattern I don't think you'll see functions like this in stdlib
👍 1