6 ms·
is that modeled on ruby ?
by agumonkey 6y ago
is that modeled on ruby ?
- vvillena 6y agoThis is a very common idiom in Scala. Function definition is slightly different, but usage is the same.
- agumonkey 6y agoAny example ? or an idiom name I can google ?
- swsieber 6y agoGroovy also does it. I have no idea what the name is though: https://mrhaki.blogspot.com/2009/11/groovy-goodness-passing-closures-to.html?m=1 https://mrhaki.blogspot.com/2009/11/groovy-goodness-passing-...
- jayrhynas 6y agoSwift calls it trailing closure syntax
- agumonkey 6y agoOk so it's an explicit parameter, the function is just ~curried so you can just write it nicely.
- matsemann 6y agoNot 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.
- matsemann 6y agoCan't edit, but here's an explanation https://kotlinlang.org/docs/reference/type-safe-builders.html https://kotlinlang.org/docs/reference/type-safe-builders.htm...
- untog 6y agoI don't know, but you can do the exact same thing in Swift.
- pjmlp 6y agoNot at all, it is very common in ML languages, Smalltalk, and even Groovy already had it.
- agumonkey 6y agoI never saw that idiom in any ml classes.. I'm honestly surprised
- pjmlp 6y agoIt 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.