1use crate::{Ability, Fx, State};
2
3use super::handler::Handler;
4
5impl<'f, I, S, O> Ability<'f, I, S, O>
6where
7 O: Clone,
8 S: Clone + 'f,
9 I: Clone + 'f,
10{
11 pub fn request(i: I) -> Fx<'f, (Self, S), O>
12 where
13 I: Clone,
14 {
15 State::get().flat_map(|f: Self| f.apply(i))
16 }
17
18 pub fn handler<B, V>(self) -> Handler<'f, (Self, B), B, V, V>
19 where
20 B: Clone,
21 V: Clone,
22 {
23 Handler::new(|e: Fx<'f, (Self, B), V>| e.provide_left(self))
24 }
25
26 pub fn imap<Y, F>(self, imap: F) -> Ability<'f, Y, S, O>
27 where
28 Y: Clone + 'f,
29 F: FnOnce(Y) -> I + Clone + 'f,
30 {
31 Ability::new(|y: Y| self.apply(imap(y)))
32 }
33
34 pub fn hmap<T, U, H>(self, h: H) -> Ability<'f, I, T, U>
35 where
36 T: Clone + 'f,
37 U: Clone + 'f,
38 H: FnOnce(Fx<'f, S, O>) -> Fx<'f, T, U> + Clone + 'f,
39 {
40 Ability::new(|i: I| h(self.apply(i)))
41 }
42}