/
package.scala
288 lines (238 loc) · 9.75 KB
/
package.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/**
* '''Scalaz''': Type classes and pure functional data structures for Scala.
*
* This package, [[scalaz]], contains:
* - type class definitions
* - data structures
* - related functions
*
* Type class instances and other functions related to the Scala and Java standard library
* are in [[scalaz.std]]
*
* Implicit conversions and wrapper classes that provide a more convenient syntax for accessing
* the functionality of the library are in [[scalaz.syntax]].
*
* '''Type Classes Index'''
*
* - [[scalaz.Semigroup]]
* - [[scalaz.Monoid]] extends [[scalaz.Semigroup]]
* - [[scalaz.Equal]]
* - [[scalaz.Show]]
* - [[scalaz.Order]] extends [[scalaz.Equal]]
* - [[scalaz.Enum]] extends [[scalaz.Order]]
*
* - [[scalaz.Plus]]
* - [[scalaz.PlusEmpty]] extends [[scalaz.Plus]]
* - [[scalaz.IsEmpty]] extends [[scalaz.PlusEmpty]]
* - [[scalaz.Optional]]
* - [[scalaz.InvariantFunctor]]
* - [[scalaz.Functor]] extends [[scalaz.InvariantFunctor]]
* - [[scalaz.Contravariant]] extends [[scalaz.InvariantFunctor]]
* - [[scalaz.Divide]] extends [[scalaz.Contravariant]]
* - [[scalaz.Divisible]] extends [[scalaz.Divide]]
* - [[scalaz.Apply]] extends [[scalaz.Functor]]
* - [[scalaz.Applicative]] extends [[scalaz.Apply]]
* - [[scalaz.Align]] extends [[scalaz.Functor]]
* - [[scalaz.Zip]]
* - [[scalaz.Unzip]]
* - [[scalaz.Cozip]]
* - [[scalaz.Bind]] extends [[scalaz.Apply]]
* - [[scalaz.BindRec]] extends [[scalaz.Bind]]
* - [[scalaz.Monad]] extends [[scalaz.Applicative]] with [[scalaz.Bind]]
* - [[scalaz.Cobind]] extends [[scalaz.Functor]]
* - [[scalaz.Comonad]] extends [[scalaz.Cobind]]
* - [[scalaz.ApplicativePlus]] extends [[scalaz.Applicative]] with [[scalaz.PlusEmpty]]
* - [[scalaz.MonadPlus]] extends [[scalaz.Monad]] with [[scalaz.ApplicativePlus]]
* - [[scalaz.Foldable]]
* - [[scalaz.Foldable1]] extends [[scalaz.Foldable]]
* - [[scalaz.Traverse]] extends [[scalaz.Functor]] with [[scalaz.Foldable]]
* - [[scalaz.Traverse1]] extends [[scalaz.Traverse]] with [[scalaz.Foldable1]]
*
* - [[scalaz.Associative]]
* - [[scalaz.Bifunctor]]
* - [[scalaz.Bifoldable]]
* - [[scalaz.Bitraverse]] extends [[scalaz.Bifunctor]] with [[scalaz.Bifoldable]]
* - [[scalaz.Catchable]]
* - [[scalaz.Nondeterminism]] extends [[scalaz.Monad]]
* - [[scalaz.Compose]]
* - [[scalaz.Profunctor]]
* - [[scalaz.Strong]] extends [[scalaz.Profunctor]]
* - [[scalaz.ProChoice]] extends [[scalaz.Profunctor]]
* - [[scalaz.Category]] extends [[scalaz.Compose]]
* - [[scalaz.Choice]] extends [[scalaz.Category]]
* - [[scalaz.Split]] extends [[scalaz.Compose]]
* - [[scalaz.Arrow]] extends [[scalaz.Split]] with [[scalaz.Strong]] with [[scalaz.Category]]
* - [[scalaz.MonadState]] extends [[scalaz.Monad]]
* - [[scalaz.MonadError]] extends [[scalaz.Monad]]
* - [[scalaz.MonadTell]] extends [[scalaz.Monad]]
* - [[scalaz.MonadReader]] extends [[scalaz.Monad]]
* - [[scalaz.ComonadStore]] extends [[scalaz.Comonad]]
*
* '''Data Structures Index'''
* - [[scalaz.Validation]] Represent computations that may succeed or fail, accumulating multiple errors.
* - [[scalaz.NonEmptyList]] A list containing at least one element.
* - [[scalaz.DList]] A difference list, supporting efficient append and prepend.
* - [[scalaz.EphemeralStream]] A stream that holds weak references to its elements, and recomputes them if needed
* if reclaimed by the garbage collector.
* - [[scalaz.Heap]] A priority queue, implemented with bootstrapped skew binomial heaps.
* - [[scalaz.Endo]] Represents functions from `A => A`.
* - [[scalaz.FingerTree]] A tree containing elements at it's leaves, and measures at the nodes. Can be adapted to
* various purposes by choosing a different measure, for example [[scalaz.IndSeq]] and [[scalaz.OrdSeq]].
* - [[scalaz.Lens]] Composable, functional alternative to getters and setters
* - [[scalaz.Tree]] A multiway tree. Each node contains a single element, and a `Stream` of sub-trees.
* - [[scalaz.TreeLoc]] A cursor over a [[scalaz.Tree]].
* - [[scalaz.Zipper]] A functional cursor over a List.
*
* - [[scalaz.Kleisli]] Represents a function `A => M[B]`, allowing chaining. Also known, and aliased, as `scalaz.ReaderT`.
* - [[scalaz.StateT]] Computations that modify state.
* - [[scalaz.WriterT]] Computations that log a value
* - [[scalaz.OptionT]] Represents computations of type `F[Option[A]]`
* - [[scalaz.MaybeT]] Represents computations of type `F[Maybe[A]]`
* - [[scalaz.EitherT]] Represents computations of type `F[A \/ B]`
*/
package object scalaz {
import Id._
val idInstance: Traverse1[Id] with Monad[Id] with BindRec[Id] with Comonad[Id] with Distributive[Id] with Zip[Id] with Unzip[Id] with Align[Id] with Cozip[Id] with Optional[Id] = Id.id
/**
* Tag a type `T` with `Tag`.
*
* The resulting type is used to discriminate between type class instances.
*
* @see [[scalaz.Tag]] and [[scalaz.Tags]]
*
* Credit to Miles Sabin for the idea.
*/
type @@[T, Tag] = scalaz.Tag.k.@@[T, Tag]
/** A [[scalaz.NaturalTransformation]][F, G]. */
type ~>[F[_], G[_]] = NaturalTransformation[F, G]
/** A [[scalaz.NaturalTransformation]][G, F]. */
type <~[F[_], G[_]] = NaturalTransformation[G, F]
type ~~>[F[_,_], G[_,_]] = BiNaturalTransformation[F, G]
/** `(A === B)` is a supertype of `Leibniz[L,H,A,B]` */
type ===[A,B] = Leibniz[⊥, ⊤, A, B]
type ⊥ = Nothing
type ⊤ = Any
type ∨[A, B] = A \/ B
type ReaderT[E, F[_], A] = Kleisli[F, E, A]
type =?>[E, A] = Kleisli[Option, E, A]
/** @template */
type Reader[E, A] = ReaderT[E, Id, A]
/** @template */
type Writer[W, A] = WriterT[W, Id, A]
/** @template */
type Unwriter[W, A] = UnwriterT[Id, W, A]
/** @template */
type StateT[S, F[_], A] = IndexedStateT[S, S, F, A]
/** @template */
type IndexedState[S1, S2, A] = IndexedStateT[S1, S2, Id, A]
/** A state transition, representing a function `S => (S, A)`.
*
* @template
*/
type State[S, A] = StateT[S, Id, A]
/** @template */
type StoreT[F[_], A, B] = IndexedStoreT[F, A, A, B]
/** @template */
type IndexedStore[I, A, B] = IndexedStoreT[Id, I, A, B]
/** @template */
type Store[A, B] = StoreT[Id, A, B]
// flipped
type |-->[A, B] = Store[B, A]
/** @template */
type Traced[A, B] = TracedT[Id, A, B]
def Traced[A, B](f: A => B): Traced[A, B] = TracedT[Id, A, B](f)
/** @template */
type ReaderWriterStateT[R, W, S, F[_], A] = IndexedReaderWriterStateT[R, W, S, S, F, A]
/** @template */
type IndexedReaderWriterState[R, W, S1, S2, A] = IndexedReaderWriterStateT[R, W, S1, S2, Id, A]
/** @template */
type ReaderWriterState[R, W, S, A] = ReaderWriterStateT[R, W, S, Id, A]
type IRWST[R, W, S1, S2, F[_], A] = IndexedReaderWriterStateT[R, W, S1, S2, F, A]
val IRWST: IndexedReaderWriterStateT.type = IndexedReaderWriterStateT
type IRWS[R, W, S1, S2, A] = IndexedReaderWriterState[R, W, S1, S2, A]
val IRWS: IndexedReaderWriterState.type = IndexedReaderWriterState
type RWST[R, W, S, F[_], A] = ReaderWriterStateT[R, W, S, F, A]
val RWST: ReaderWriterStateT.type = ReaderWriterStateT
type RWS[R, W, S, A] = ReaderWriterState[R, W, S, A]
val RWS: ReaderWriterState.type = ReaderWriterState
/** An [[scalaz.Validation]] with a [[scalaz.NonEmptyList]] as the failure type.
*
* @template
*
* Useful for accumulating errors through the corresponding [[scalaz.Applicative]] instance.
*/
type ValidationNel[E, X] = Validation[NonEmptyList[E], X]
type FirstOf[A] = A @@ Tags.FirstVal
type LastOf[A] = A @@ Tags.LastVal
type MinOf[A] = A @@ Tags.MinVal
type MaxOf[A] = A @@ Tags.MaxVal
type FirstOption[A] = Option[A] @@ Tags.First
type LastOption[A] = Option[A] @@ Tags.Last
type MinOption[A] = Option[A] @@ Tags.Min
type MaxOption[A] = Option[A] @@ Tags.Max
type FirstMaybe[A] = Maybe[A] @@ Tags.First
type LastMaybe[A] = Maybe[A] @@ Tags.Last
type MinMaybe[A] = Maybe[A] @@ Tags.Min
type MaxMaybe[A] = Maybe[A] @@ Tags.Max
//
// Lens type aliases
//
/** A lens that doesn't transform the type of the record.
*
* @template
* @see [[scalaz.@>]]
*/
type Lens[A, B] = LensFamily[A, A, B, B]
/** @see [[scalaz.Lens]] */
type @>[A, B] = Lens[A, B]
//
// Partial Lens type aliases
//
/** A partial lens that doesn't transform the type of the record.
*
* @template
* @see [[scalaz.@?>]]
*/
type PLens[A, B] = PLensFamily[A, A, B, B]
/** @see [[scalaz.PLens]] */
type @?>[A, B] = PLens[A, B]
/** @template */
type PIndexedStateT[F[_], S1, S2, A] = IndexedStateT[S1, S2, F, Option[A]]
/** @template */
type PStateT[F[_], S, A] = PIndexedStateT[F, S, S, A]
/** @template */
type PIndexedState[S1, S2, A] = PIndexedStateT[Id, S1, S2, A]
/** @template */
type PState[S, A] = PStateT[Id, S, A]
/** @template */
type IndexedConts[W[_], R, O, A] = IndexedContsT[W, R, O, Id, A]
/** @template */
type IndexedContT[R, O, M[_], A] = IndexedContsT[Id, R, O, M, A]
/** @template */
type IndexedCont[R, O, A] = IndexedContT[R, O, Id, A]
/** @template */
type ContsT[W[_], R, M[_], A] = IndexedContsT[W, R, R, M, A]
/** @template */
type Conts[W[_], R, A] = ContsT[W, R, Id, A]
/** @template */
type ContT[R, M[_], A] = ContsT[Id, R, M, A]
/** @template */
type Cont[R, A] = ContT[R, Id, A]
/** @template */
type Select[R, A] = SelectT[R, Id, A]
/** [[scalaz.Inject]][F, G] */
type :<:[F[_], G[_]] = Inject[F, G]
/** [[scalaz.Inject]][F, G] */
type :≺:[F[_], G[_]] = Inject[F, G]
type IMap[A, B] = ==>>[A, B]
val IMap = ==>>
type Disjunction[A, B] = \/[A, B]
val Disjunction = \/
type DLeft[A, B] = -\/[A, B]
val DLeft = -\/
type DRight[A, B] = \/-[A, B]
val DRight = \/-
type DisjunctionT[A, F[_], B] = EitherT[A, F, B]
val DisjunctionT = EitherT
type Pair[A] = (A, A)
}