Given this Scala code:
def compute2(maybeFoo: Option[Foo]): Option[Int] =
maybeFoo.flatMap { foo =>
foo.bar.flatMap { bar =>
bar.baz.map { baz =>
baz.compute
}
}
}
Which is then translated to this for comprehension:
def compute2(maybeFoo: Option[Foo]): Option[Int] =
for {
foo <- maybeFoo
bar <- foo.bar
baz <- bar.baz
} yield baz.compute
My question is How to convert this map/flatMap into a for comprehension in Clojure?
Assumptions:
- If possible I'd like to use idiomatic Clojure (ie
mapcat
) to represent this rather than thealgo.monads
/fluokitten
libraries. But if that is the best way to do it (I'm open to learning) then use that.