raulraja
05/16/2018, 6:07 PMsyntax
function to the Companions such as that most of the important type classes a data type implements are exposed as the single this
scope in the function block.
Where before you'd have to access the functions accesing the instances like in the example below:
Option.applicative().map(Option(1), Option(1), Option(1), { (a, b, c) -> a + b + c }) //Option(3)
Option.monad().binding {
val a = Option(1).bind()
val b = Option(a + 1).bind()
a + b
}
// Option(3)
Option.functor()...
Option.traverse()...
Now you can just use the syntax object to access all the imported extension functions and static ones in the scope like in the example below:
import arrow.instances.*
Option syntax { //`this` is Monad, Applicative, Functor, Traverse, etc...
binding { ... }
map(....)
traverse(...)
}
Either<String>() syntax { //`this` is Monad, Applicative, Functor, Traverse, etc...
binding { ... }
map(....)
traverse(...)
}
If anyone has any feedback about the DSL or naming beside syntax
feedback and ideas are welcome!
Thanks!