-
-
Save joegaudet/9ada6cae7fb58fd3338d1d34e4d7563d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val eventuallyFoo = ServiceOne.get // can be fired in parallel | |
val eventuallyBar = ServiceTwo.get | |
val maybeBax = Option(...) | |
for { | |
foo <- eventuallyFoo | |
sideEffect = maybeBax.getOrElse('dooo') | |
bar <- eventuallyBar | |
baz <- DB.get(foo.id, bar.id, sideEffect) | |
if baz.someCondition | |
} yield baz | |
// de sugars to | |
eventuallyFoo.flatMap((foo) => { | |
val sideEffect = maybeBaz.getOrElse('doo') // this is an option | |
eventuallBar.flatMap((bar) => | |
DB.get(foo.id, bar.id, sideEffect) | |
.flatMap(baz => { | |
baz.filter(_ => _.someCondition) | |
.map(_ => baz) | |
} | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment