Say we have an object (e.g. a list) in Scala, and we want to sequence user-defined functions with object member functions, for instance:
g(l.map(f)
.foldRight(...))
.map(h)
If the sequence of functions is larger, the code gets a little messy. Is there a better way to write such a code? Maybe something like:
l.map(f)
.foldRight(...)
.call(g) // call would simply call function g on the resulting object
.map(h)
Using
scala.util.chaining._you can re-writeas
https://github.com/scala/scala/blob/v2.13.10/src/library/scala/util/ChainingOps.scala
https://blog.knoldus.com/new-chaining-operations-in-scala-2-13/
https://alvinalexander.com/scala/scala-2.13-pipe-tap-chaining-operations/