News for hackers. Stuff that matters.
Re:Crystal 0.25.1 released by andyfleming on Friday June 29, 2018 @02:35PM (#17426569)
Kotlin syntax:

"1 2 3".split(' ').map { it.toInt() }

Re:Crystal 0.25.1 released by yxhuvud on Friday June 29, 2018 @04:34PM (#17427652)
Your example doesn't do the same thing.

The same as grandparent, in crystal:

  "1 2 3".split.map &.to_i.*(2)
Re:Crystal 0.25.1 released by pmontra on Friday June 29, 2018 @06:14PM (#17428259)
I believe that Ruby also has that & shortcut (or similar) but it's totally unreadable. I never used it and I don't even want to check the exact syntax. Is it the only way it works in Crystal?
Re:Crystal 0.25.1 released by yxhuvud on Saturday June 30, 2018 @03:31AM (#17429893)
It being readable is a matter of getting used to it. I find it more readable than the block version as there is less syntactic boilerplate. YMMV.

Ruby has a similar version using colon instead of dot but that version isn't chainable and doesn't take arguments so it can't do the *2.

And no, you can write out the full block just as you did in the Ruby version.

Re:Crystal 0.25.1 released by andyfleming on Friday June 29, 2018 @04:56PM (#17427809)
Whoops, you're right.

    "1 2 3".split(' ').map { it.toInt() * 2 }