2 ms·
In Scala it's called blocks [0], and if a function/method expects one you can provide it inline, eg: myList.foreach { x => doTheThingToTheThingEvery(x, 100
by pas 5y ago
In Scala it's called blocks [0], and if a function/method expects one you can provide it inline, eg:
myList.foreach { x => doTheThingToTheThingEvery(x, 100 millis) }
Of course it's sometimes a bit too much. It starts out cute [1] and handy [2][3][4], then [5] ... [6] :)
[0] https://docs.scala-lang.org/tour/basics.html#blocks https://docs.scala-lang.org/tour/basics.html#blocks
[1] https://scastie.scala-lang.org/tpfgE80WTc6QQaHslraJag https://scastie.scala-lang.org/tpfgE80WTc6QQaHslraJag
[2] https://www.playframework.com/documentation/2.8.x/ScalaActions#Building-an-Action https://www.playframework.com/documentation/2.8.x/ScalaActio...
[3] https://stackoverflow.com/q/50370202/44166 https://stackoverflow.com/q/50370202/44166
[5] https://www.playframework.com/documentation/2.8.x/ScalaActionsComposition#More-complicated-actions https://www.playframework.com/documentation/2.8.x/ScalaActio...
[6] https://miro.medium.com/max/784/1*EMiSTuRIxUPCzWOgLkiXoA.jpeg https://miro.medium.com/max/784/1*EMiSTuRIxUPCzWOgLkiXoA.jpe...
- melolife 5y agoScala doesn't really have a name for this, it simply permits you to provide a block in lieu of a parenthesized argument list. Given that blocks are expressions: val a = { val x = 2; x + 1 } the syntax you are describing is just a function-valued block.