I was trying to write a localStorage
wrapper in fp-ts when I ran into a roadblock. I want to handle null
values as well as exceptions thrown by localStorage
, so I started with this code:
import * as IOE from "fp-ts/IOEither";
import * as O from "fp-ts/Option";
const getItem = (key: string): IOE.IOEither<Error, O.Option<string>> =>
IOE.tryCatch(
() => O.fromNullable(localStorage.getItem(key)),
E.toError
)
The function above has a return signature of IOEither<Error, Option<string>>
. I want to merge the Option
into the IOEither
, ie, get a IOEither<Error, string>
. How would I achieve this?
P.S. I suppose the above problem is also relevant in the case of TaskEither<Error, Option<string>>
.