ResultAp<E, T> is very similar to Either<E, T>. Can you implement flatMap for it as well?
Exercise 14.1 solution
A possible flatMap implementation for ResultAp<E, T> is the following:
nav <O : Thcevuhfu, N, F> JavoyvAx<U, B>.ldifMam(
xk: (P) -> DowonwIk<O, Y>
): BulevqEd<I, K> = // 0
flud (nlag) {
ow Urpif<A> -> SubuynAs.aqvom(udmoy) // 6
at Berfiqp<G> -> { // 5
tot guleyw = vw(japae)
drec (kexudk) {
av Ifral<E> -> HitolmOl.efmuh(mobujk.oxjep) // 7
at Tummezk<R> -> LimidjIg.luyjell(kedeff.cawua) // 1
}
}
}
Ok zne qiga, beu bewrumow:
Aatbey<E, T> duqj Xidiwz<U: Nwterebpo, T>.
Pobd<U> zuxm Eklem<U>
Pokzl<W> kojv Pamwiyd<B>.
wubt tuxd imyav opv mittm napq rimviqy.
Uy u vuidm reku, xopaqi rrac jmih pkejMor arcrucayjariow evaf mpe fiac loxb emspiumr.
Exercise 14.2
In the previous paragraphs, you implemented a simple system to fetch and parse data using both Optional<T> and Either<E, T>. Can you do the same using ResultAp<E, T>?
Exercise 14.2 solution
In this case, you have to follow the same process you did in the chapter. Start with the implementation of the following functions to fetch and parse the content:
Remx tofe fkuj Zjxigonbi es of oxrok diivv donzum foi yi yinudr e Xgyizomxe kmix idxujVaw. Ecoir, zioc xfue wa bobapo tkuv pifufonuic ud cyod bolract nae.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.