Created
November 9, 2019 09:44
-
-
Save nomisRev/66e71d9b05190a0168825c1eb94db1fc to your computer and use it in GitHub Desktop.
Impure Pics - Shared state in fp
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
| fun add1(myState: Ref<ForIO, List<String>>): IO<Unit> = | |
| IO.sleep(5.seconds).followedBy(myState.update { it + listOf("#1") }) | |
| fun add2(myState: Ref<ForIO, List<String>>): IO<Unit> = | |
| IO.sleep(3.seconds).followedBy(myState.update { it + listOf("#2") }) | |
| fun read(myState: Ref<ForIO, List<String>>): IO<Unit> = | |
| myState.get().effectMap { state -> println("$state") } | |
| suspend fun main(): Unit = IO.fx { | |
| val myState = !Ref(emptyList<String>()) | |
| !listOf(add1(myState), add2(myState)).parSequence() | |
| !read(myState) | |
| }.suspended() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment