Re:Kotlin 1.4
by agumonkey on Tuesday August 18, 2020 @08:37AM
(#24197874)
is that modeled on ruby ?
[ Parent
| on HN ]
This is a very common idiom in Scala. Function definition is slightly different, but usage is the same.
Any example ? or an idiom name I can google ?
Groovy also does it. I have no idea what the name is though: https://mrhaki.blogspot.com/2009/11/groovy-goodness-passing-...
Not sure about the exact name. But kotlin also has "function with receiver" that together with this makes it very easy to write almost a custom domain language on top of kotlin.
Can't edit, but here's an explanation https://kotlinlang.org/docs/reference/type-safe-builders.htm...
Swift calls it trailing closure syntax
Ok so it's an explicit parameter, the function is just ~curried so you can just write it nicely.
Not at all, it is very common in ML languages, Smalltalk, and even Groovy already had it.
I never saw that idiom in any ml classes.. I'm honestly surprised
It is a common idiom for dealing with deterministic resource management, and takes advantage that in ML all functions are single parameter actually.
So you can partially specialize, and then the lambda gets the already allocated/opened resource, thus acting as region/arena resource allocator.
And you can combine it with currying to apply the concept to multiple kind of parameters.