There are multiple use cases for currying and part...
# language-proposals
r
There are multiple use cases for currying and partial application. A few of them here: http://www.vasinov.com/blog/on-currying-and-partial-function-application/ https://lukajcb.github.io/blog/scala/2016/03/08/a-real-world-currying-example.html The main use case for me is to be able to create specialized functions with good semantics from bigger functions that can also act on their own if invoked with all parameters. Here is an example from Luka's post linked above adapted to Kotlin:
Copy code
data class CreditCard(val creditInfo: CreditCardInfo, val issuer: Person, val account: Account) {
  companion object {
    fun getPremium(totalCards: Int)(creditCard: CreditCard): Double = TODO() //note the two param groups
  }
}
val creditCards: List<CreditCard> = getCreditCards()

// here the first param group is applied with _ resulting in a function that only needs the second param `creditcard`
val getPremiumWithTotal = CreditCard.getPremium(creditCards.length) _ 

val allPremiums = creditCards.map(getPremiumWithTotal).sum
Here we can decompose a bigger function
CreditCard#getPremium
into smaller reusable functions
getPremiumWithTotal
. As a bonus we are adapting the function to fit in
List#map
as function reference getting simpler syntax. I would also argue that with the incoming number of devs coming to Kotlin from other langs that are not Java and used to currying and partial application that's also frustrating to them. Not having that frustration is as valid as arguing that Java folks are gonna be scared. Currying and Partial Aplication are possible in Kotlin and cover many use cases but it's just boilerplate: https://github.com/arrow-kt/arrow/blob/master/arrow-syntax/src/main/kotlin/arrow/syntax/function/partials.kt Something to consider about currying and Partial Application is that in Kotlin we have suspended functions in coroutines and I'm not positive how those would be impacted by such a feature