|
6 | 6 | // Copyright (c) 2015 TypeLift. All rights reserved. |
7 | 7 | // Released under the MIT License. |
8 | 8 | // |
9 | | -// Precedence marks for certain symbols aligned with Runes |
| 9 | +// Precedence marks for certain symbols aligned with Runes |
10 | 10 | // ~( https://github.com/thoughtbot/Runes/blob/master/Source/Runes.swift ) until Swift gets a proper |
11 | 11 | // resolver. |
12 | 12 |
|
13 | 13 | // MARK: Combinators |
14 | 14 |
|
| 15 | +precedencegroup CompositionPrecedence { |
| 16 | + associativity: right |
| 17 | + higherThan: BitwiseShiftPrecedence |
| 18 | +} |
| 19 | + |
15 | 20 | /// Compose | Applies one function to the result of another function to produce a third function. |
16 | | -infix operator • { |
17 | | - associativity right |
18 | | - precedence 190 |
| 21 | +infix operator • : CompositionPrecedence |
| 22 | + |
| 23 | +precedencegroup RightAssociativeCombinatorPrecedence { |
| 24 | + associativity: right |
| 25 | + lowerThan: DefaultPrecedence |
19 | 26 | } |
20 | 27 |
|
21 | | -/// Apply | Applies an argument to a function. |
22 | | -infix operator § { |
23 | | - associativity right |
24 | | - precedence 95 |
| 28 | +precedencegroup LeftAssociativeCombinatorPrecedence { |
| 29 | + associativity: left |
| 30 | + lowerThan: DefaultPrecedence |
25 | 31 | } |
26 | 32 |
|
| 33 | +/// Apply | Applies an argument to a function. |
| 34 | +infix operator § : RightAssociativeCombinatorPrecedence |
| 35 | + |
27 | 36 | /// Pipe Backward | Applies the function to its left to an argument on its right. |
28 | | -infix operator <| { |
29 | | - associativity right |
30 | | - precedence 95 |
31 | | -} |
| 37 | +infix operator <| : RightAssociativeCombinatorPrecedence |
32 | 38 |
|
33 | 39 | /// Pipe forward | Applies an argument on the left to a function on the right. |
34 | | -infix operator |> { |
35 | | - associativity left |
36 | | - precedence 95 |
37 | | -} |
| 40 | +infix operator |> : LeftAssociativeCombinatorPrecedence |
38 | 41 |
|
39 | 42 | /// On | Given a "combining" function and a function that converts arguments to the target of the |
40 | 43 | /// combiner, returns a function that applies the right hand side to two arguments, then runs both |
41 | 44 | /// results through the combiner. |
42 | | -infix operator |*| { |
43 | | - associativity left |
44 | | - precedence 100 |
| 45 | +infix operator |*| : LeftAssociativeCombinatorPrecedence |
| 46 | + |
| 47 | +// MARK: Control.* |
| 48 | + |
| 49 | +precedencegroup FunctorPrecedence { |
| 50 | + associativity: left |
| 51 | + higherThan: DefaultPrecedence |
45 | 52 | } |
46 | 53 |
|
| 54 | +precedencegroup FunctorSequencePrecedence { |
| 55 | + associativity: left |
| 56 | + higherThan: FunctorPrecedence |
| 57 | +} |
47 | 58 |
|
48 | | -// MARK: Control.* |
| 59 | +precedencegroup MonadPrecedenceLeft { |
| 60 | + associativity: left |
| 61 | + higherThan: FunctorSequencePrecedence |
| 62 | +} |
49 | 63 |
|
50 | | -/// Fmap | Maps a function over the value encapsulated by a functor. |
51 | | -infix operator <^> { |
52 | | - associativity left |
53 | | - // https://github.com/thoughtbot/Runes/blob/master/Source/Runes.swift |
54 | | - precedence 130 |
| 64 | +precedencegroup MonadPrecedenceRight { |
| 65 | + associativity: right |
| 66 | + higherThan: FunctorSequencePrecedence |
55 | 67 | } |
56 | 68 |
|
| 69 | +/// Fmap | Maps a function over the value encapsulated by a functor. |
| 70 | +infix operator <^> : FunctorPrecedence |
| 71 | + |
57 | 72 | /// Replace | Maps all the values encapsulated by a functor to a user-specified constant. |
58 | | -infix operator <^ { |
59 | | - associativity left |
60 | | - precedence 140 |
61 | | -} |
| 73 | +infix operator <^ : FunctorSequencePrecedence |
62 | 74 |
|
63 | 75 | /// Replace Backwards | Maps all the values encapsulated by a functor to a user-specified constant. |
64 | | -infix operator ^> { |
65 | | - associativity left |
66 | | - precedence 140 |
67 | | -} |
| 76 | +infix operator ^> : FunctorSequencePrecedence |
68 | 77 |
|
69 | 78 |
|
70 | 79 | /// Ap | Applies a function encapsulated by a functor to the value encapsulated by another functor. |
71 | | -infix operator <*> { |
72 | | - associativity left |
73 | | - // https://github.com/thoughtbot/Runes/blob/master/Source/Runes.swift |
74 | | - precedence 130 |
75 | | -} |
| 80 | +infix operator <*> : FunctorPrecedence |
76 | 81 |
|
77 | 82 | /// Sequence Right | Disregards the Functor on the Left. |
78 | 83 | /// |
79 | 84 | /// Default definition: |
80 | | -/// `const(id) <^> a <*> b` |
81 | | -infix operator *> { |
82 | | - associativity left |
83 | | - precedence 140 |
84 | | -} |
| 85 | +/// `const(id) <^> a <*> b` |
| 86 | +infix operator *> : FunctorSequencePrecedence |
85 | 87 |
|
86 | 88 | /// Sequence Left | Disregards the Functor on the Right. |
87 | 89 | /// |
88 | 90 | /// Default definition: |
89 | | -/// `const <^> a <*> b` |
90 | | -infix operator <* { |
91 | | - associativity left |
92 | | - precedence 140 |
93 | | -} |
| 91 | +/// `const <^> a <*> b` |
| 92 | +infix operator <* : FunctorSequencePrecedence |
94 | 93 |
|
95 | 94 | /// Bind | Sequences and composes two monadic actions by passing the value inside the monad on the |
96 | 95 | /// left to a function on the right yielding a new monad. |
97 | | -infix operator >>- { |
98 | | - associativity left |
99 | | - // https://github.com/thoughtbot/Runes/blob/master/Source/Runes.swift |
100 | | - precedence 100 |
101 | | -} |
| 96 | +infix operator >>- : MonadPrecedenceLeft |
102 | 97 |
|
103 | | -/// Bind Backwards | Composes two monadic actions by passing the value inside the monad on the |
| 98 | +/// Bind Backwards | Composes two monadic actions by passing the value inside the monad on the |
104 | 99 | /// right to the funciton on the left. |
105 | | -infix operator -<< { |
106 | | - associativity right |
107 | | - // https://github.com/thoughtbot/Runes/blob/master/Source/Runes.swift |
108 | | - precedence 100 |
109 | | -} |
| 100 | +infix operator -<< : MonadPrecedenceRight |
110 | 101 |
|
111 | 102 | /// Left-to-Right Kleisli | Composition for monads. |
112 | | -infix operator >>->> { |
113 | | - associativity right |
114 | | - precedence 110 |
115 | | -} |
| 103 | +infix operator >>->> : MonadPrecedenceRight |
116 | 104 |
|
117 | 105 | /// Right-to-Left Kleisli | Composition for monads. |
118 | | -infix operator <<-<< { |
119 | | - associativity right |
120 | | - precedence 110 |
121 | | -} |
| 106 | +infix operator <<-<< : MonadPrecedenceRight |
122 | 107 |
|
123 | 108 | /// Extend | Duplicates the surrounding context and computes a value from it while remaining in the |
124 | 109 | /// original context. |
125 | | -infix operator ->> { |
126 | | - associativity left |
127 | | - precedence 110 |
| 110 | +infix operator ->> : MonadPrecedenceLeft |
| 111 | + |
| 112 | +precedencegroup FunctorExtrasPrecedence { |
| 113 | + associativity: left |
| 114 | + higherThan: FunctorSequencePrecedence |
128 | 115 | } |
129 | 116 |
|
130 | 117 | /// Imap | Maps covariantly over the index of a right-leaning bifunctor. |
131 | | -infix operator <^^> { |
132 | | - associativity left |
133 | | - precedence 140 |
134 | | -} |
| 118 | +infix operator <^^> : FunctorExtrasPrecedence |
135 | 119 |
|
136 | 120 | /// Contramap | Contravariantly maps a function over the value encapsulated by a functor. |
137 | | -infix operator <!> { |
138 | | - associativity left |
139 | | - precedence 140 |
140 | | -} |
| 121 | +infix operator <!> : FunctorExtrasPrecedence |
141 | 122 |
|
142 | 123 | // MARK: Data.Result |
143 | 124 |
|
144 | | -/// From | Creates a Result given a function that can possibly fail with an error. |
145 | | -infix operator !! { |
146 | | - associativity none |
147 | | - precedence 120 |
| 125 | +precedencegroup ResultPrecedence { |
| 126 | + associativity: none |
| 127 | + higherThan: FunctorPrecedence |
148 | 128 | } |
149 | 129 |
|
| 130 | +/// From | Creates a Result given a function that can possibly fail with an error. |
| 131 | +infix operator !! : ResultPrecedence |
| 132 | + |
150 | 133 | // MARK: Data.Monoid |
151 | 134 |
|
152 | 135 | /// Append | Alias for a Semigroup's operation. |
153 | | -infix operator <> { |
154 | | - associativity right |
155 | | - precedence 160 |
156 | | -} |
| 136 | +infix operator <> : AdditionPrecedence |
157 | 137 |
|
158 | 138 | // MARK: Control.Category |
159 | 139 |
|
| 140 | +precedencegroup CategoryPrecedence { |
| 141 | + associativity: right |
| 142 | + higherThan: MonadPrecedenceRight |
| 143 | +} |
| 144 | + |
160 | 145 | /// Right-to-Left Composition | Composes two categories to form a new category with the source of |
161 | 146 | /// the second category and the target of the first category. |
162 | 147 | /// |
163 | 148 | /// This function is literally `•`, but for Categories. |
164 | | -infix operator <<< { |
165 | | - associativity right |
166 | | - precedence 110 |
167 | | -} |
| 149 | +infix operator <<< : CategoryPrecedence |
168 | 150 |
|
169 | 151 | /// Left-to-Right Composition | Composes two categories to form a new category with the source of |
170 | 152 | /// the first category and the target of the second category. |
171 | 153 | /// |
172 | 154 | /// Function composition with the arguments flipped. |
173 | | -infix operator >>> { |
174 | | - associativity right |
175 | | - precedence 110 |
176 | | -} |
| 155 | +infix operator >>> : CategoryPrecedence |
177 | 156 |
|
178 | 157 | // MARK: Control.Arrow |
179 | 158 |
|
| 159 | +precedencegroup ArrowPrecedence { |
| 160 | + associativity: right |
| 161 | + higherThan: CategoryPrecedence |
| 162 | +} |
| 163 | + |
180 | 164 | /// Split | Splits two computations and combines the result into one Arrow yielding a tuple of |
181 | 165 | /// the result of each side. |
182 | | -infix operator *** { |
183 | | - associativity right |
184 | | - precedence 130 |
185 | | -} |
| 166 | +infix operator *** : ArrowPrecedence |
186 | 167 |
|
187 | 168 | /// Fanout | Given two functions with the same source but different targets, this function |
188 | 169 | /// splits the computation and combines the result of each Arrow into a tuple of the result of |
189 | 170 | /// each side. |
190 | | -infix operator &&& { |
191 | | - associativity right |
192 | | - precedence 130 |
193 | | -} |
| 171 | +infix operator &&& : ArrowPrecedence |
194 | 172 |
|
195 | 173 | // MARK: Control.Arrow.Choice |
196 | 174 |
|
197 | | -/// Splat | Splits two computations and combines the results into Eithers on the left and right. |
198 | | -infix operator +++ { |
199 | | - associativity right |
200 | | - precedence 120 |
| 175 | +precedencegroup ArrowChoicePrecedence { |
| 176 | + associativity: right |
| 177 | + higherThan: ArrowPrecedence |
201 | 178 | } |
202 | 179 |
|
| 180 | +/// Splat | Splits two computations and combines the results into Eithers on the left and right. |
| 181 | +infix operator +++ : ArrowChoicePrecedence |
| 182 | + |
203 | 183 | /// Fanin | Given two functions with the same target but different sources, this function splits |
204 | 184 | /// the input between the two and merges the output. |
205 | | -infix operator ||| { |
206 | | - associativity right |
207 | | - precedence 120 |
208 | | -} |
| 185 | +infix operator ||| : ArrowChoicePrecedence |
209 | 186 |
|
210 | 187 | // MARK: Control.Arrow.Plus |
211 | 188 |
|
212 | | -/// Op | Combines two ArrowZero monoids. |
213 | | -infix operator <+> { |
214 | | - associativity right |
215 | | - precedence 150 |
| 189 | +precedencegroup ArrowPlusPrecedence { |
| 190 | + associativity: right |
| 191 | + higherThan: ArrowChoicePrecedence |
216 | 192 | } |
217 | 193 |
|
| 194 | +/// Op | Combines two ArrowZero monoids. |
| 195 | +infix operator <+> : ArrowPlusPrecedence |
| 196 | + |
218 | 197 | // MARK: Data.JSON |
219 | 198 |
|
220 | | -/// Retrieve | Retrieves a value from a dictionary of JSON values using a given keypath. |
221 | | -/// |
222 | | -/// If the given keypath is not present or the retrieved value is not of the appropriate type, this |
223 | | -/// function returns `.None`. |
224 | | -infix operator <? { |
225 | | - associativity left |
226 | | - precedence 150 |
| 199 | +precedencegroup JSONPrecedence { |
| 200 | + associativity: right |
| 201 | + higherThan: ArrowPlusPrecedence |
227 | 202 | } |
228 | 203 |
|
229 | | -/// Retrieve | Retrieves an optional value from a dictionary of JSON values using a given keypath. |
230 | | -/// This is used for retrieving an Optional value for a value that is itself an Optional. |
| 204 | +/// Retrieve | Retrieves a value from a dictionary of JSON values using a given keypath. |
231 | 205 | /// |
232 | 206 | /// If the given keypath is not present or the retrieved value is not of the appropriate type, this |
233 | 207 | /// function returns `.None`. |
234 | | -infix operator <?? { |
235 | | - associativity left |
236 | | - precedence 150 |
237 | | -} |
| 208 | +infix operator <? : JSONPrecedence |
238 | 209 |
|
239 | 210 | /// Force Retrieve | Retrieves a value from a dictionary of JSON values using a given keypath, |
240 | 211 | /// forcing any Optionals it finds. |
241 | 212 | /// |
242 | 213 | /// If the given keypath is not present or the retrieved value is not of the appropriate type, this |
243 | 214 | /// function will terminate with a fatal error. It is recommended that you use Force Retrieve's |
244 | 215 | /// total cousin `<?` (Retrieve). |
245 | | -infix operator <! { |
246 | | - associativity left |
247 | | - precedence 150 |
248 | | -} |
| 216 | +infix operator <! : JSONPrecedence |
249 | 217 |
|
250 | 218 | // MARK: Data.Set |
251 | 219 |
|
252 | 220 | /// Intersection | Returns the intersection of two sets. |
253 | | -infix operator ∩ {} |
| 221 | +infix operator ∩ |
254 | 222 |
|
255 | 223 | /// Union | Returns the union of two sets. |
256 | | -infix operator ∪ {} |
| 224 | +infix operator ∪ |
0 commit comments