Hi, is there a cleaner way to do this: ``` class I...
# arrow
k
Hi, is there a cleaner way to do this:
Copy code
class InMemoryStorePersistentSource : IStorePersistentSource {

    private var store: IO<Option<Store>> = IO { None }

    override fun getCurrentStore(): IO<Option<Store>> = store
    override fun persistCurrentStore(store: Option<Store>): IO<Unit> = IO { this.store = IO { store } }
}
r
Hi @kluck Assuming that is the interpreter of an algebra like:
Copy code
interface IStorePersistentSource {
  fun getCurrentStore(): IO<Option<Store>>
  fun persistCurrentStore(store: Option<Store>): IO<Unit>
}
It is fine since the effect of replacing the store is encapsulated in the IO constructor and you can still replace the interpreter in tests. No need for
IO { None }
because it’s inefficient since that constructor is lazy and you already have a computed pure value. That should be instead
IO.just(None)
.
k
Oh, nice, I didn't know about the difference between
IO {}
and
IO.just()
. Thanks!
I now have to replace it in loooots of places 😛
😂 2
p
We have an IO.unit or IO.unit() constructor IIRC