(no title)
t0mek | 2 years ago
fun double(x: Int) = x * 2
https://kotlinlang.org/docs/functions.html#single-expression...However, in Kotlin there's no single-line constraint, so it's possible to define an expression function e.g. with a long chain of collection methods: `filter().map().findFirst()...`
marcellus23|2 years ago
edit: in my original version of this comment I forgot to add the return type syntax, "-> Int", which Swift needs. I suppose eliding the return type is a bit more terse. You could also assign a closure in Swift to avoid that, like:
which is about as short as the Kotlin version, and has the advantage of not being "special" in any sense from any other Swift syntax (i.e., it's just assigning a standard closure to a variable).dragonwriter|2 years ago
adamgordonbell|2 years ago
Was a bit of fun in scala to see if you could rewrite something to be a single statement.
Sometimes the single statement version wasn't clearer, but sometimes it really was.
Point free programming takes this to code golf type territory and can be fun as a puzzle if not for real world code.
Maybe ruby just doesn't do it well?
MrBuddyCasino|2 years ago