1use crate::*;
2
3pub trait UnsizedExt {
4 fn ap<TCon, TIn, TOut, TFunc, X>(
5 &self,
6 x: &X
7 ) -> <TCon as WithTypeArg<TOut>>::Type
8 where
9 Self: TypeApp<TCon, TFunc>,
10 TCon: Applicative + WithTypeArg<TFunc> + WithTypeArg<TIn> + WithTypeArg<TOut>,
11 TFunc: Fn(&TIn) -> TOut,
12 X: TypeApp<TCon, TIn> + ?Sized,
13 {
14 ap(self, x)
15 }
16
17 fn bind<TCon, TIn, TOut, F, TResult>(&self, f: F) -> TResult
18 where
19 TCon: Monad + WithTypeArg<TIn> + WithTypeArg<TOut> + ?Sized,
20 F: Fn(&TIn) -> TResult,
21 TResult: TypeApp<TCon, TOut>,
22 Self: TypeApp<TCon, TIn>,
23 {
24 bind(self, f)
25 }
26
27 fn bind_ignore<TCon, TIn, TOut, TResult>(&self, y: &TResult) -> TResult
28 where
29 TCon: Monad + WithTypeArg<TIn> + WithTypeArg<TOut> + ?Sized,
30 Self: TypeApp<TCon, TIn>,
31 TResult: TypeApp<TCon, TOut>,
32 <TCon as WithTypeArg<TOut>>::Type: Clone,
33 {
34 bind_ignore(self, y)
35 }
36
37 fn fjoin<TCon, T, TInner>(&self) -> <TCon as WithTypeArg<T>>::Type
38 where
39 TCon: Monad
40 + WithTypeArg<T>
41 + WithTypeArg<TInner>
42 + WithTypeArg<<TCon as WithTypeArg<T>>::Type>
43 + ?Sized,
44 Self: TypeApp<TCon, TInner>,
45 TInner: TypeApp<TCon, T>,
46 <TCon as WithTypeArg<T>>::Type: Clone,
47 {
48 fjoin(self)
49 }
50}
51
52impl<T> UnsizedExt for T {}
53
54pub trait SizedExt: Sized {
55 fn lift<TCon>(self) -> <TCon as WithTypeArg<Self>>::Type
56 where
57 TCon: Lift + WithTypeArg<Self> + ?Sized,
58 {
59 lift::<TCon, Self>(self)
60 }
61
62 fn lap<TCon, TIn, TOut, TFunc, X>(
63 self,
64 x: X,
65 ) -> <TCon as WithTypeArg<TOut>>::Type
66 where
67 TCon: LinearApplicative
68 + WithTypeArg<TFunc>
69 + WithTypeArg<TIn>
70 + WithTypeArg<TOut>
71 + ?Sized,
72 Self: TypeApp<TCon, TFunc>,
73 TFunc: Fn(TIn) -> TOut,
74 X: TypeApp<TCon, TIn>,
75 {
76 <TCon as LinearApplicative>::lap::<TIn, TOut, TFunc>(self.into_val(), x.into_val())
77 }
78
79 fn lmap<TCon, TIn, TOut, X>(
80 self,
81 x: X,
82 ) -> <TCon as WithTypeArg<TOut>>::Type
83 where
84 TCon: LinearFunctor + WithTypeArg<TIn> + WithTypeArg<TOut> + ?Sized,
85 Self: Fn(TIn) -> TOut,
86 X: TypeApp<TCon, TIn>
87 {
88 lmap(self, x)
89 }
90
91 fn lmapop<TCon, TIn, TOut, F>(self, f: F) -> <TCon as WithTypeArg<TOut>>::Type
92 where
93 TCon: LinearFunctor + WithTypeArg<TIn> + WithTypeArg<TOut> + ?Sized,
94 Self: TypeApp<TCon, TIn>,
95 F: Fn(TIn) -> TOut
96 {
97 lmap(f, self)
98 }
99
100 fn fmap<TCon, TIn, TOut, X>(self, x: &X) -> <TCon as WithTypeArg<TOut>>::Type
101 where
102 TCon: Functor + WithTypeArg<TIn> + WithTypeArg<TOut> + ?Sized,
103 Self: Fn(&TIn) -> TOut,
104 X: TypeApp<TCon, TIn> + ?Sized
105 {
106 fmap(self, x)
107 }
108
109 fn fmapop<TCon, TIn, TOut, F>(&self, f: F) -> <TCon as WithTypeArg<TOut>>::Type
110 where
111 TCon: Functor + WithTypeArg<TIn> + WithTypeArg<TOut> + ?Sized,
112 Self: TypeApp<TCon, TIn>,
113 F: Fn(&TIn) -> TOut
114 {
115 fmap(f, self)
116 }
117
118 fn lbind<TCon, TIn, TOut, F, TResult>(self, f: F) -> TResult
119 where
120 TCon: LinearMonad + WithTypeArg<TIn> + WithTypeArg<TOut> + ?Sized,
121 F: Fn(TIn) -> TResult,
122 TResult: TypeApp<TCon, TOut>,
123 Self: TypeApp<TCon, TIn>,
124 {
125 lbind(self, f)
126 }
127
128 fn lbind_ignore<TCon, TIn, TOut, TResult>(self, y: &TResult) -> TResult
129 where
130 TCon: LinearMonad + WithTypeArg<TIn> + WithTypeArg<TOut> + ?Sized,
131 Self: TypeApp<TCon, TIn>,
132 TResult: TypeApp<TCon, TOut>,
133 <TCon as WithTypeArg<TOut>>::Type: Clone,
134 {
135 lbind_ignore(self, y)
136 }
137}
138
139impl<T: Sized> SizedExt for T {}