|
| 1 | +// |
| 2 | +// Operators.swift |
| 3 | +// Operadics |
| 4 | +// |
| 5 | +// Created by Robert Widmann on 07/07/2015. |
| 6 | +// Copyright (c) 2015 TypeLift. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +/// MARK: Combinators |
| 10 | + |
| 11 | +/// Compose | Applies one function to the result of another function to produce a third function. |
| 12 | +infix operator • { |
| 13 | + associativity right |
| 14 | + precedence 190 |
| 15 | +} |
| 16 | + |
| 17 | +/// Apply | Applies an argument to a function. |
| 18 | +infix operator § { |
| 19 | + associativity right |
| 20 | + precedence 0 |
| 21 | +} |
| 22 | + |
| 23 | +/// Pipe Backward | Applies the function to its left to an argument on its right. |
| 24 | +infix operator <| { |
| 25 | + associativity right |
| 26 | + precedence 0 |
| 27 | +} |
| 28 | + |
| 29 | +/// Pipe forward | Applies an argument on the left to a function on the right. |
| 30 | +infix operator |> { |
| 31 | + associativity left |
| 32 | + precedence 0 |
| 33 | +} |
| 34 | + |
| 35 | +/// MARK: Control.* |
| 36 | + |
| 37 | +/// Fmap | Maps a function over the value encapsulated by a functor. |
| 38 | +infix operator <^> { |
| 39 | + associativity left |
| 40 | + precedence 140 |
| 41 | +} |
| 42 | + |
| 43 | +/// Ap | Applies a function encapsulated by a functor to the value encapsulated by another functor. |
| 44 | +infix operator <*> { |
| 45 | + associativity left |
| 46 | + precedence 140 |
| 47 | +} |
| 48 | + |
| 49 | +/// Bind | Sequences and composes two monadic actions by passing the value inside the monad on the |
| 50 | +/// left to a function on the right yielding a new monad. |
| 51 | +infix operator >>- { |
| 52 | + associativity left |
| 53 | + precedence 110 |
| 54 | +} |
| 55 | + |
| 56 | +/// Extend | Duplicates the surrounding context and computes a value from it while remaining in the |
| 57 | +/// original context. |
| 58 | +infix operator ->> { |
| 59 | + associativity left |
| 60 | + precedence 110 |
| 61 | +} |
| 62 | + |
| 63 | +/// MARK: Data.Result |
| 64 | + |
| 65 | +/// From | Creates a Result given a function that can possibly fail with an error. |
| 66 | +infix operator !! { |
| 67 | + associativity none |
| 68 | + precedence 120 |
| 69 | +} |
| 70 | + |
| 71 | +/// MARK: Data.Monoid |
| 72 | + |
| 73 | +/// Append | Alias for a Semigroup's operation. |
| 74 | +infix operator <> { |
| 75 | + associativity right |
| 76 | + precedence 160 |
| 77 | +} |
| 78 | + |
| 79 | +/// MARK: Control.Category |
| 80 | + |
| 81 | +/// Right-to-Left Composition | Composes two categories to form a new category with the source of |
| 82 | +/// the second category and the target of the first category. |
| 83 | +/// |
| 84 | +/// This function is literally `•`, but for Categories. |
| 85 | +infix operator <<< { |
| 86 | + precedence 110 |
| 87 | + associativity right |
| 88 | +} |
| 89 | + |
| 90 | +/// Left-to-Right Composition | Composes two categories to form a new category with the source of |
| 91 | +/// the first category and the target of the second category. |
| 92 | +/// |
| 93 | +/// Function composition with the arguments flipped. |
| 94 | +infix operator >>> { |
| 95 | + precedence 110 |
| 96 | + associativity right |
| 97 | +} |
| 98 | + |
| 99 | +/// MARK: Control.Arrow |
| 100 | + |
| 101 | +/// Split | Splits two computations and combines the result into one Arrow yielding a tuple of |
| 102 | +/// the result of each side. |
| 103 | +infix operator *** { |
| 104 | + precedence 130 |
| 105 | + associativity right |
| 106 | +} |
| 107 | + |
| 108 | +/// Fanout | Given two functions with the same source but different targets, this function |
| 109 | +/// splits the computation and combines the result of each Arrow into a tuple of the result of |
| 110 | +/// each side. |
| 111 | +infix operator &&& { |
| 112 | + precedence 130 |
| 113 | + associativity right |
| 114 | +} |
| 115 | + |
| 116 | +/// MARK: Control.Arrow.Choice |
| 117 | + |
| 118 | +/// Splat | Splits two computations and combines the results into Eithers on the left and right. |
| 119 | +infix operator +++ { |
| 120 | + precedence 120 |
| 121 | + associativity right |
| 122 | +} |
| 123 | + |
| 124 | +/// Fanin | Given two functions with the same target but different sources, this function splits |
| 125 | +/// the input between the two and merges the output. |
| 126 | +infix operator ||| { |
| 127 | + precedence 120 |
| 128 | + associativity right |
| 129 | +} |
| 130 | + |
| 131 | +/// MARK: Control.Arrow.Plus |
| 132 | + |
| 133 | +/// Op | Combines two ArrowZero monoids. |
| 134 | +infix operator <+> { |
| 135 | + precedence 150 |
| 136 | + associativity right |
| 137 | +} |
| 138 | + |
| 139 | +/// MARK: Data.JSON |
| 140 | + |
| 141 | +/// Retrieve | Retrieves a value from a dictionary of JSON values using a given keypath. |
| 142 | +/// |
| 143 | +/// If the given keypath is not present or the retrieved value is not of the appropriate type, this |
| 144 | +/// function returns `.None`. |
| 145 | +infix operator <? { |
| 146 | + precedence 150 |
| 147 | + associativity left |
| 148 | +} |
| 149 | + |
| 150 | +/// Force Retrieve | Retrieves a value from a dictionary of JSON values using a given keypath, |
| 151 | +/// forcing any Optionals it finds. |
| 152 | +/// |
| 153 | +/// If the given keypath is not present or the retrieved value is not of the appropriate type, this |
| 154 | +/// function will terminate with a fatal error. It is recommended that you use Force Retrieve's |
| 155 | +/// total cousin `<?` (Retrieve). |
| 156 | +infix operator <! { |
| 157 | + precedence 150 |
| 158 | + associativity left |
| 159 | +} |
| 160 | + |
| 161 | +/// MARK: Data.Set |
| 162 | + |
| 163 | +/// Intersection | Returns the intersection of two sets. |
| 164 | +infix operator ∩ {} |
| 165 | + |
| 166 | +/// Union | Returns the union of two sets. |
| 167 | +infix operator ∪ {} |
0 commit comments