Skip to content

Commit 6e58952

Browse files
committed
Merge pull request #1 from typelift/monad-special-ops
Monad Special Ops
2 parents 0cf4ba9 + 734e51d commit 6e58952

File tree

1 file changed

+60
-10
lines changed

1 file changed

+60
-10
lines changed

Operators.swift

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Released under the MIT License.
88
//
99

10-
/// MARK: Combinators
10+
// MARK: Combinators
1111

1212
/// Compose | Applies one function to the result of another function to produce a third function.
1313
infix operator {
@@ -42,27 +42,77 @@ infix operator |*| {
4242
}
4343

4444

45-
/// MARK: Control.*
45+
// MARK: Control.*
4646

4747
/// Fmap | Maps a function over the value encapsulated by a functor.
4848
infix operator <^> {
4949
associativity left
5050
precedence 140
5151
}
5252

53+
/// Replace | Maps all the values encapsulated by a functor to a user-specified constant.
54+
infix operator <^ {
55+
associativity left
56+
precedence 140
57+
}
58+
59+
/// Replace Backwards | Maps all the values encapsulated by a functor to a user-specified constant.
60+
infix operator ^> {
61+
associativity left
62+
precedence 140
63+
}
64+
65+
5366
/// Ap | Applies a function encapsulated by a functor to the value encapsulated by another functor.
5467
infix operator <*> {
5568
associativity left
5669
precedence 140
5770
}
5871

72+
/// Sequence Right | Disregards the Functor on the Left.
73+
///
74+
/// Default definition:
75+
/// `const(id) <^> a <*> b`
76+
infix operator *> {
77+
associativity left
78+
precedence 140
79+
}
80+
81+
/// Sequence Left | Disregards the Functor on the Right.
82+
///
83+
/// Default definition:
84+
/// `const <^> a <*> b`
85+
infix operator <* {
86+
associativity left
87+
precedence 140
88+
}
89+
5990
/// Bind | Sequences and composes two monadic actions by passing the value inside the monad on the
6091
/// left to a function on the right yielding a new monad.
6192
infix operator >>- {
6293
associativity left
6394
precedence 110
6495
}
6596

97+
/// Bind Backwards | Composes two monadic actions by passing the value inside the monad on the
98+
/// right to the funciton on the left.
99+
infix operator -<< {
100+
associativity right
101+
precedence 110
102+
}
103+
104+
/// Left-to-Right Kleisli |
105+
infix operator >>->> {
106+
associativity right
107+
precedence 110
108+
}
109+
110+
/// Right-to-Left Kleisli |
111+
infix operator <<-<< {
112+
associativity right
113+
precedence 110
114+
}
115+
66116
/// Extend | Duplicates the surrounding context and computes a value from it while remaining in the
67117
/// original context.
68118
infix operator ->> {
@@ -82,23 +132,23 @@ infix operator <!> {
82132
precedence 140
83133
}
84134

85-
/// MARK: Data.Result
135+
// MARK: Data.Result
86136

87137
/// From | Creates a Result given a function that can possibly fail with an error.
88138
infix operator !! {
89139
associativity none
90140
precedence 120
91141
}
92142

93-
/// MARK: Data.Monoid
143+
// MARK: Data.Monoid
94144

95145
/// Append | Alias for a Semigroup's operation.
96146
infix operator <> {
97147
associativity right
98148
precedence 160
99149
}
100150

101-
/// MARK: Control.Category
151+
// MARK: Control.Category
102152

103153
/// Right-to-Left Composition | Composes two categories to form a new category with the source of
104154
/// the second category and the target of the first category.
@@ -118,7 +168,7 @@ infix operator >>> {
118168
precedence 110
119169
}
120170

121-
/// MARK: Control.Arrow
171+
// MARK: Control.Arrow
122172

123173
/// Split | Splits two computations and combines the result into one Arrow yielding a tuple of
124174
/// the result of each side.
@@ -135,7 +185,7 @@ infix operator &&& {
135185
precedence 130
136186
}
137187

138-
/// MARK: Control.Arrow.Choice
188+
// MARK: Control.Arrow.Choice
139189

140190
/// Splat | Splits two computations and combines the results into Eithers on the left and right.
141191
infix operator +++ {
@@ -150,15 +200,15 @@ infix operator ||| {
150200
precedence 120
151201
}
152202

153-
/// MARK: Control.Arrow.Plus
203+
// MARK: Control.Arrow.Plus
154204

155205
/// Op | Combines two ArrowZero monoids.
156206
infix operator <+> {
157207
associativity right
158208
precedence 150
159209
}
160210

161-
/// MARK: Data.JSON
211+
// MARK: Data.JSON
162212

163213
/// Retrieve | Retrieves a value from a dictionary of JSON values using a given keypath.
164214
///
@@ -180,7 +230,7 @@ infix operator <! {
180230
precedence 150
181231
}
182232

183-
/// MARK: Data.Set
233+
// MARK: Data.Set
184234

185235
/// Intersection | Returns the intersection of two sets.
186236
infix operator {}

0 commit comments

Comments
 (0)