ivanmorgillo
04/30/2020, 4:36 PMfun <T> load(key: String): IO<NoValueFoundForKey, T> {...}
on the lower layer and then mapping it to a higher layer with something like this:
override fun areRemindersEnabled(): IO<Nothing, Boolean> {
val storedReminderSettings: IO<NoValueFoundForKey, Boolean> = storage.load(key)
return storedReminderSettings
.map { areEnabled -> IO.just(areEnabled) }
.handleErrorWith { IO.just(false) }
}
I'm thinking of fun areRemindersEnabled(): IO<Nothing, Boolean> because I would like to take care of the possible errors and allow consumers to just get a Boolean in every situation.
I thought I could pass through the boolean if everything is fine and handle the error and propagate a boolean if things go south.
At the moment I'm stuck because types don't match. I'm not confident on the syntax or the whole approach either.
I'm experimenting here to be able to understand how to use IO and proposing it effectively to my teams.
Any pointer, please?