1use crate::functor::Functor;
2use crate::hkt::HKT;
3
4pub trait Extend<B>: Functor<B> + Sized {
5 fn extend<W>(self, f: W) -> <Self as HKT<B>>::Target
6 where
7 W: FnOnce(Self) -> B;
8}
9
10impl<A, B> Extend<B> for Option<A> {
11 fn extend<W>(self, f: W) -> Self::Target
12 where
13 W: FnOnce(Self) -> B,
14 {
15 self.map(|x| f(Some(x)))
16 }
17}
18
19impl<A, B, E> Extend<B> for Result<A, E> {
20 fn extend<W>(self, f: W) -> Self::Target
21 where
22 W: FnOnce(Self) -> B,
23 {
24 self.map(|x| f(Ok(x)))
25 }
26}