Skip to content

Commit 464d5c1

Browse files
authored
Merge pull request #6 from typelift/precedencecolinensinainciusol
Update to precedencegroup syntax
2 parents 8117a84 + b827525 commit 464d5c1

File tree

1 file changed

+101
-133
lines changed

1 file changed

+101
-133
lines changed

Operators.swift

Lines changed: 101 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -6,251 +6,219 @@
66
// Copyright (c) 2015 TypeLift. All rights reserved.
77
// Released under the MIT License.
88
//
9-
// Precedence marks for certain symbols aligned with Runes
9+
// Precedence marks for certain symbols aligned with Runes
1010
// ~( https://github.com/thoughtbot/Runes/blob/master/Source/Runes.swift ) until Swift gets a proper
1111
// resolver.
1212

1313
// MARK: Combinators
1414

15+
precedencegroup CompositionPrecedence {
16+
associativity: right
17+
higherThan: BitwiseShiftPrecedence
18+
}
19+
1520
/// 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
1926
}
2027

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
2531
}
2632

33+
/// Apply | Applies an argument to a function.
34+
infix operator § : RightAssociativeCombinatorPrecedence
35+
2736
/// 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
3238

3339
/// 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
3841

3942
/// On | Given a "combining" function and a function that converts arguments to the target of the
4043
/// combiner, returns a function that applies the right hand side to two arguments, then runs both
4144
/// 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
4552
}
4653

54+
precedencegroup FunctorSequencePrecedence {
55+
associativity: left
56+
higherThan: FunctorPrecedence
57+
}
4758

48-
// MARK: Control.*
59+
precedencegroup MonadPrecedenceLeft {
60+
associativity: left
61+
higherThan: FunctorSequencePrecedence
62+
}
4963

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
5567
}
5668

69+
/// Fmap | Maps a function over the value encapsulated by a functor.
70+
infix operator <^> : FunctorPrecedence
71+
5772
/// 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
6274

6375
/// 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
6877

6978

7079
/// 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
7681

7782
/// Sequence Right | Disregards the Functor on the Left.
7883
///
7984
/// 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
8587

8688
/// Sequence Left | Disregards the Functor on the Right.
8789
///
8890
/// Default definition:
89-
/// `const <^> a <*> b`
90-
infix operator <* {
91-
associativity left
92-
precedence 140
93-
}
91+
/// `const <^> a <*> b`
92+
infix operator <* : FunctorSequencePrecedence
9493

9594
/// Bind | Sequences and composes two monadic actions by passing the value inside the monad on the
9695
/// 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
10297

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
10499
/// 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
110101

111102
/// Left-to-Right Kleisli | Composition for monads.
112-
infix operator >>->> {
113-
associativity right
114-
precedence 110
115-
}
103+
infix operator >>->> : MonadPrecedenceRight
116104

117105
/// Right-to-Left Kleisli | Composition for monads.
118-
infix operator <<-<< {
119-
associativity right
120-
precedence 110
121-
}
106+
infix operator <<-<< : MonadPrecedenceRight
122107

123108
/// Extend | Duplicates the surrounding context and computes a value from it while remaining in the
124109
/// 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
128115
}
129116

130117
/// 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
135119

136120
/// 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
141122

142123
// MARK: Data.Result
143124

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
148128
}
149129

130+
/// From | Creates a Result given a function that can possibly fail with an error.
131+
infix operator !! : ResultPrecedence
132+
150133
// MARK: Data.Monoid
151134

152135
/// Append | Alias for a Semigroup's operation.
153-
infix operator <> {
154-
associativity right
155-
precedence 160
156-
}
136+
infix operator <> : AdditionPrecedence
157137

158138
// MARK: Control.Category
159139

140+
precedencegroup CategoryPrecedence {
141+
associativity: right
142+
higherThan: MonadPrecedenceRight
143+
}
144+
160145
/// Right-to-Left Composition | Composes two categories to form a new category with the source of
161146
/// the second category and the target of the first category.
162147
///
163148
/// This function is literally `•`, but for Categories.
164-
infix operator <<< {
165-
associativity right
166-
precedence 110
167-
}
149+
infix operator <<< : CategoryPrecedence
168150

169151
/// Left-to-Right Composition | Composes two categories to form a new category with the source of
170152
/// the first category and the target of the second category.
171153
///
172154
/// Function composition with the arguments flipped.
173-
infix operator >>> {
174-
associativity right
175-
precedence 110
176-
}
155+
infix operator >>> : CategoryPrecedence
177156

178157
// MARK: Control.Arrow
179158

159+
precedencegroup ArrowPrecedence {
160+
associativity: right
161+
higherThan: CategoryPrecedence
162+
}
163+
180164
/// Split | Splits two computations and combines the result into one Arrow yielding a tuple of
181165
/// the result of each side.
182-
infix operator *** {
183-
associativity right
184-
precedence 130
185-
}
166+
infix operator *** : ArrowPrecedence
186167

187168
/// Fanout | Given two functions with the same source but different targets, this function
188169
/// splits the computation and combines the result of each Arrow into a tuple of the result of
189170
/// each side.
190-
infix operator &&& {
191-
associativity right
192-
precedence 130
193-
}
171+
infix operator &&& : ArrowPrecedence
194172

195173
// MARK: Control.Arrow.Choice
196174

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
201178
}
202179

180+
/// Splat | Splits two computations and combines the results into Eithers on the left and right.
181+
infix operator +++ : ArrowChoicePrecedence
182+
203183
/// Fanin | Given two functions with the same target but different sources, this function splits
204184
/// the input between the two and merges the output.
205-
infix operator ||| {
206-
associativity right
207-
precedence 120
208-
}
185+
infix operator ||| : ArrowChoicePrecedence
209186

210187
// MARK: Control.Arrow.Plus
211188

212-
/// Op | Combines two ArrowZero monoids.
213-
infix operator <+> {
214-
associativity right
215-
precedence 150
189+
precedencegroup ArrowPlusPrecedence {
190+
associativity: right
191+
higherThan: ArrowChoicePrecedence
216192
}
217193

194+
/// Op | Combines two ArrowZero monoids.
195+
infix operator <+> : ArrowPlusPrecedence
196+
218197
// MARK: Data.JSON
219198

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
227202
}
228203

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.
231205
///
232206
/// If the given keypath is not present or the retrieved value is not of the appropriate type, this
233207
/// function returns `.None`.
234-
infix operator <?? {
235-
associativity left
236-
precedence 150
237-
}
208+
infix operator <? : JSONPrecedence
238209

239210
/// Force Retrieve | Retrieves a value from a dictionary of JSON values using a given keypath,
240211
/// forcing any Optionals it finds.
241212
///
242213
/// If the given keypath is not present or the retrieved value is not of the appropriate type, this
243214
/// function will terminate with a fatal error. It is recommended that you use Force Retrieve's
244215
/// total cousin `<?` (Retrieve).
245-
infix operator <! {
246-
associativity left
247-
precedence 150
248-
}
216+
infix operator <! : JSONPrecedence
249217

250218
// MARK: Data.Set
251219

252220
/// Intersection | Returns the intersection of two sets.
253-
infix operator {}
221+
infix operator
254222

255223
/// Union | Returns the union of two sets.
256-
infix operator {}
224+
infix operator

0 commit comments

Comments
 (0)