Welcome! Got a question? Do you have -Ypartial-unification turned on? Other FAQs: http://typelevel.org/cats/faq.html
for
very rarely, and don't really recommend it if you're starting out with IO
(it clouds the picture)
Resource
and Stream
Resource
, there is one place (the big resource in main
where you build the world) where for
is usually distinctly prettier than explicit combinators, so I'd use for
if I was on my own. In a codebase shared with beginners I'd take the ugliness though and avoid for
even then
for
is shared by many people :) )
def
vs val
dichotomy (for being and doing), and we spend a lot of time discussing how FP shifts the focus to composing programs instead, where doing
is expressed through combinators
for
shifts you back to to the previous dichotomy (<-
vs =
), and now you have three layers of abstraction to deal with
val a = operation
def a = operation
for
has the same mental model, you can either do with <-
, or be with =
val
vs def
doesn't matter) and do is expressed explicitly by combinators that compose programs
for {
a <- doThis
_ <- doThat(a)
}...
doesn't really convey the composition of programs, doThis.flatMap(doThat)
does (and generalises to doThis.race(doThat)
, doThis.orElse(doThat)
etc
Ok, how to properly handle errors in for comprehensions?
case in point :)
handleErrorWith
, which is more natural outside a for