scala - Monadic coding style? -
scala - Monadic coding style? -
i find myself writing programs more , more in style this:
mylist .map(el => ...) .filter(_....) .map { el => ... ... } .zipwithindex .foreach(println)
often subroutine consists exclusively of such block of code. never planned alter style of coding this, happened naturally used scala more , more.
is right such code written in "monadic style"? have vague understanding of monad is, , using scala's collections here, , seem monadic types. on other hand not creating monadic types myself, using them. in other words, when want simply programme in take_something.change_it.change_it.use_it
style, ok refer "monadic style"?
i programming way consequence of using monads, i'd describe programming in monadic style if you're relying on monads programme free of side-effects, using things io monads , state monads. tend end whole bunch of nested (as opposed chained) map
s, flatmap
s, , filter
s. scala for...yield
build helps organize code works multiple nested monads. may find book functional programming in scala interesting, delving style.
your illustration monadic in smaller sense of using chained transformations on 1 monadic type. pattern used in lot of code wouldn't describe "monadic", , called method cascading or fluent pattern.
scala coding-style monads
Comments
Post a Comment