-
Notifications
You must be signed in to change notification settings - Fork 451
/
Copy pathTraversal.kt
658 lines (590 loc) · 21.7 KB
/
Traversal.kt
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
package arrow.optics
import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.Option
import arrow.core.Tuple10
import arrow.core.Tuple4
import arrow.core.Tuple5
import arrow.core.Tuple6
import arrow.core.Tuple7
import arrow.core.Tuple8
import arrow.core.Tuple9
import arrow.core.identity
import arrow.typeclasses.Monoid
import kotlin.jvm.JvmStatic
/**
* [Traversal] is a type alias for [PTraversal] which fixes the type arguments
* and restricts the [PTraversal] to monomorphic updates.
*/
public typealias Traversal<S, A> = PTraversal<S, S, A, A>
/**
* A [Traversal] is an optic that allows to see into a structure with 0 to N foci.
*
* [Traversal] is a generalisation of [kotlin.collections.map] and can be seen as a representation of modify.
* all methods are written in terms of modify
*
* @param S the source of a [PTraversal]
* @param T the modified source of a [PTraversal]
* @param A the target of a [PTraversal]
* @param B the modified target of a [PTraversal]
*/
public interface PTraversal<S, T, A, B> {
/**
* Map each target to a type R and use a Monoid to fold the results
*/
public fun <R> foldMap(M: Monoid<R>, source: S, map: (focus: A) -> R): R
/**
* Modify polymorphically the focus of a [PTraversal] with a function [map].
*/
public fun modify(source: S, map: (focus: A) -> B): T
/**
* Set polymorphically the focus of a [PTraversal] with a value [focus].
*/
public fun set(source: S, focus: B): T =
modify(source) { focus }
/**
* Lift a function [map]: `(A) -> B to the context of `S`: `(S) -> T`
*/
public fun lift(map: (focus: A) -> B): (source: S) -> T =
{ s -> modify(s) { map(it) } }
/**
* Join two [PTraversal] with the same target
*/
public fun <U, V> choice(other: PTraversal<U, V, A, B>): PTraversal<Either<S, U>, Either<T, V>, A, B> =
object : PTraversal<Either<S, U>, Either<T, V>, A, B> {
override fun <R> foldMap(M: Monoid<R>, source: Either<S, U>, map: (A) -> R): R =
source.fold(
{ a -> [email protected](M, a, map) },
{ u -> other.foldMap(M, u, map) }
)
override fun modify(source: Either<S, U>, map: (focus: A) -> B): Either<T, V> =
source.fold(
{ a -> Either.Left([email protected](a, map)) },
{ u -> Either.Right(other.modify(u, map)) }
)
}
/**
* Compose a [PTraversal] with a [PTraversal]
*/
public infix fun <C, D> compose(other: PTraversal<in A, out B, out C, in D>): PTraversal<S, T, C, D> =
object : PTraversal<S, T, C, D> {
override fun <R> foldMap(M: Monoid<R>, source: S, map: (C) -> R): R =
[email protected](M, source) { c -> other.foldMap(M, c, map) }
override fun modify(source: S, map: (focus: C) -> D): T =
[email protected](source) { b -> other.modify(b, map) }
}
public operator fun <C, D> plus(other: PTraversal<in A, out B, out C, in D>): PTraversal<S, T, C, D> =
this compose other
/**
* Calculate the number of targets
*/
public fun size(source: S): Int =
foldMap(Monoid.int(), source) { 1 }
/**
* Check if all targets satisfy the predicate
*/
public fun all(source: S, predicate: (focus: A) -> Boolean): Boolean =
foldMap(Monoid.boolean(), source, predicate)
/**
* Returns `true` if at least one focus matches the given [predicate].
*/
public fun any(source: S, predicate: (focus: A) -> Boolean): Boolean =
foldMap(Monoid.booleanOr(), source, predicate)
/**
* Check if there is no target
*/
public fun isEmpty(source: S): Boolean =
foldMap(Monoid.boolean(), source) { false }
/**
* Check if there is at least one target
*/
public fun isNotEmpty(source: S): Boolean =
!isEmpty(source)
/**
* Get the first target or null
*/
@Suppress("UNCHECKED_CAST")
public fun firstOrNull(source: S): A? {
val fold = ::fold as (Monoid<Any?>, S) -> Any?
val res = fold(object : Monoid<Any?> {
override fun empty(): Any = EMPTY_VALUE
override fun append(a: Any?, b: Any?): Any? =
if (a === EMPTY_VALUE) b else a
}, source)
return EMPTY_VALUE.unbox(res)
}
/**
* Get the last target or null
*/
@Suppress("UNCHECKED_CAST")
public fun lastOrNull(source: S): A? {
val fold = ::fold as (Monoid<Any?>, S) -> Any?
val res = fold(object : Monoid<Any?> {
override fun empty(): Any = EMPTY_VALUE
override fun append(a: Any?, b: Any?): Any? =
if (b !== EMPTY_VALUE) b else a
}, source)
return EMPTY_VALUE.unbox(res)
}
/**
* Fold using the given [Monoid] instance.
*/
public fun fold(M: Monoid<@UnsafeVariance A>, source: S): A =
foldMap(M, source, ::identity)
/**
* Alias for fold.
*/
@Deprecated("use fold instead", ReplaceWith("fold(M, source)"))
public fun combineAll(M: Monoid<@UnsafeVariance A>, source: S): A =
fold(M, source)
/**
* Get all targets of the [Traversal]
*/
public fun getAll(source: S): List<A> =
foldMap(Monoid.list(), source, ::listOf)
/**
* Find the first element matching the predicate, if one exists.
*/
public fun findOrNull(source: S, predicate: (focus: A) -> Boolean): A? {
val res = foldMap(object : Monoid<Any?> {
override fun empty(): Any = EMPTY_VALUE
override fun append(a: Any?, b: Any?): Any? =
if (a === EMPTY_VALUE) b else a
}, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE }
return EMPTY_VALUE.unbox(res)
}
/**
* Check whether at least one element satisfies the predicate.
*
* If there are no elements, the result is false.
*/
public fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean {
val res = foldMap(object : Monoid<Any?> {
override fun empty(): Any = EMPTY_VALUE
override fun append(a: Any?, b: Any?): Any? =
if (a === EMPTY_VALUE) b else a
}, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE }
return res !== EMPTY_VALUE
}
public companion object {
public fun <S> id(): Traversal<S, S> = PLens.id()
public fun <S> codiagonal(): Traversal<Either<S, S>, S> =
object : Traversal<Either<S, S>, S> {
override fun <R> foldMap(M: Monoid<R>, source: Either<S, S>, map: (focus: S) -> R): R =
source.fold(
{ a -> map(a) },
{ u -> map(u) }
)
override fun modify(source: Either<S, S>, map: (focus: S) -> S): Either<S, S> =
source.bimap(map, map)
}
// Traversal { s, f -> s.bimap(f, f) }
/**
* [PTraversal] that points to nothing
*/
public fun <S, A> void(): Traversal<S, A> =
POptional.void()
/**
* [PTraversal] constructor from multiple getters of the same source.
*/
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
set: (B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), s)
}
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
get3: (S) -> A,
set: (B, B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), f(get3(s)), s)
}
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
get3: (S) -> A,
get4: (S) -> A,
set: (B, B, B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), s)
}
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
get3: (S) -> A,
get4: (S) -> A,
get5: (S) -> A,
set: (B, B, B, B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), s)
}
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
get3: (S) -> A,
get4: (S) -> A,
get5: (S) -> A,
get6: (S) -> A,
set: (B, B, B, B, B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), s)
}
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
get3: (S) -> A,
get4: (S) -> A,
get5: (S) -> A,
get6: (S) -> A,
get7: (S) -> A,
set: (B, B, B, B, B, B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), s)
}
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
get3: (S) -> A,
get4: (S) -> A,
get5: (S) -> A,
get6: (S) -> A,
get7: (S) -> A,
get8: (S) -> A,
set: (B, B, B, B, B, B, B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), s)
}
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
get3: (S) -> A,
get4: (S) -> A,
get5: (S) -> A,
get6: (S) -> A,
get7: (S) -> A,
get8: (S) -> A,
get9: (S) -> A,
set: (B, B, B, B, B, B, B, B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), s)
}
public operator fun <S, T, A, B> invoke(
get1: (S) -> A,
get2: (S) -> A,
get3: (S) -> A,
get4: (S) -> A,
get5: (S) -> A,
get6: (S) -> A,
get7: (S) -> A,
get8: (S) -> A,
get9: (S) -> A,
get10: (S) -> A,
set: (B, B, B, B, B, B, B, B, B, B, S) -> T
): PTraversal<S, T, A, B> =
object : PTraversal<S, T, A, B> {
override fun <R> foldMap(M: Monoid<R>, s: S, f: (focus: A) -> R): R =
M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), f(get10(s))))
override fun modify(s: S, f: (focus: A) -> B): T =
set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), f(get10(s)), s)
}
/**
* [Traversal] for [List] that focuses in each [A] of the source [List].
*/
@JvmStatic
public fun <A> list(): Traversal<List<A>, A> =
Every.list()
/**
* [Traversal] for [Either] that has focus in each [Either.Right].
*
* @receiver [PTraversal.Companion] to make it statically available.
* @return [Traversal] with source [Either] and focus every [Either.Right] of the source.
*/
@JvmStatic
public fun <L, R> either(): Traversal<Either<L, R>, R> =
Every.either()
@JvmStatic
public fun <K, V> map(): Traversal<Map<K, V>, V> =
Every.map()
/**
* [Traversal] for [NonEmptyList] that has focus in each [A].
*
* @receiver [PTraversal.Companion] to make it statically available.
* @return [Traversal] with source [NonEmptyList] and focus every [A] of the source.
*/
@JvmStatic
public fun <A> nonEmptyList(): Traversal<NonEmptyList<A>, A> =
Every.nonEmptyList()
/**
* [Traversal] for [Option] that has focus in each [arrow.core.Some].
*
* @receiver [PTraversal.Companion] to make it statically available.
* @return [Traversal] with source [Option] and focus in every [arrow.core.Some] of the source.
*/
@JvmStatic
public fun <A> option(): Traversal<Option<A>, A> =
Every.option()
@JvmStatic
public fun <A> sequence(): Traversal<Sequence<A>, A> =
Every.sequence()
/**
* [Traversal] for [String] that focuses in each [Char] of the source [String].
*
* @receiver [PTraversal.Companion] to make it statically available.
* @return [Traversal] with source [String] and foci every [Char] in the source.
*/
@JvmStatic
public fun string(): Traversal<String, Char> =
Every.string()
/**
* [PTraversal] to focus into the first and second value of a [Pair]
*/
@JvmStatic
public fun <A, B> pPair(): PTraversal<Pair<A, A>, Pair<B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
set = { a, b, _ -> a to b }
)
/**
* [Traversal] to focus into the first and second value of a [Pair]
*/
@JvmStatic
public fun <A> pair(): Traversal<Pair<A, A>, A> =
pPair()
/**
* [PTraversal] to focus into the first, second and third value of a [Triple]
*/
@JvmStatic
public fun <A, B> pTriple(): PTraversal<Triple<A, A, A>, Triple<B, B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
get3 = { it.third },
set = { a, b, c, _ -> Triple(a, b, c) }
)
/**
* [Traversal] to focus into the first, second and third value of a [Triple]
*/
@JvmStatic
public fun <A> triple(): Traversal<Triple<A, A, A>, A> =
pTriple()
/**
* [PTraversal] to focus into the first, second, third and fourth value of a [arrow.core.Tuple4]
*/
@JvmStatic
public fun <A, B> pTuple4(): PTraversal<Tuple4<A, A, A, A>, Tuple4<B, B, B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
get3 = { it.third },
get4 = { it.fourth },
set = { a, b, c, d, _ -> Tuple4(a, b, c, d) }
)
/**
* [Traversal] to focus into the first, second, third and fourth value of a [arrow.core.Tuple4]
*/
@JvmStatic
public fun <A> tuple4(): Traversal<Tuple4<A, A, A, A>, A> =
pTuple4()
/**
* [PTraversal] to focus into the first, second, third, fourth and fifth value of a [arrow.core.Tuple5]
*/
@JvmStatic
public fun <A, B> pTuple5(): PTraversal<Tuple5<A, A, A, A, A>, Tuple5<B, B, B, B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
get3 = { it.third },
get4 = { it.fourth },
get5 = { it.fifth },
set = { a, b, c, d, e, _ -> Tuple5(a, b, c, d, e) }
)
/**
* [Traversal] to focus into the first, second, third, fourth and fifth value of a [arrow.core.Tuple5]
*/
@JvmStatic
public fun <A> tuple5(): Traversal<Tuple5<A, A, A, A, A>, A> =
pTuple5()
/**
* [PTraversal] to focus into the first, second, third, fourth, fifth and sixth value of a [arrow.core.Tuple6]
*/
@JvmStatic
public fun <A, B> pTuple6(): PTraversal<Tuple6<A, A, A, A, A, A>, Tuple6<B, B, B, B, B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
get3 = { it.third },
get4 = { it.fourth },
get5 = { it.fifth },
get6 = { it.sixth },
set = { a, b, c, d, e, f, _ -> Tuple6(a, b, c, d, e, f) }
)
/**
* [Traversal] to focus into the first, second, third, fourth, fifth and sixth value of a [arrow.core.Tuple6]
*/
@JvmStatic
public fun <A> tuple6(): Traversal<Tuple6<A, A, A, A, A, A>, A> =
pTuple6()
/**
* [PTraversal] to focus into the first, second, third, fourth, fifth, sixth and seventh value of a [arrow.core.Tuple7]
*/
@JvmStatic
public fun <A, B> pTuple7(): PTraversal<Tuple7<A, A, A, A, A, A, A>, Tuple7<B, B, B, B, B, B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
get3 = { it.third },
get4 = { it.fourth },
get5 = { it.fifth },
get6 = { it.sixth },
get7 = { it.seventh },
set = { a, b, c, d, e, f, g, _ -> Tuple7(a, b, c, d, e, f, g) }
)
/**
* [Traversal] to focus into the first, second, third, fourth, fifth, sixth and seventh value of a [arrow.core.Tuple7]
*/
@JvmStatic
public fun <A> tuple7(): Traversal<Tuple7<A, A, A, A, A, A, A>, A> =
pTuple7()
/**
* [PTraversal] to focus into the first, second, third, fourth, fifth, sixth, seventh and eight value of a [arrow.core.Tuple8]
*/
@JvmStatic
public fun <A, B> pTuple8(): PTraversal<Tuple8<A, A, A, A, A, A, A, A>, Tuple8<B, B, B, B, B, B, B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
get3 = { it.third },
get4 = { it.fourth },
get5 = { it.fifth },
get6 = { it.sixth },
get7 = { it.seventh },
get8 = { it.eighth },
set = { a, b, c, d, e, f, g, h, _ -> Tuple8(a, b, c, d, e, f, g, h) }
)
/**
* [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh and eight value of a [arrow.core.Tuple8]
*/
@JvmStatic
public fun <A> tuple8(): Traversal<Tuple8<A, A, A, A, A, A, A, A>, A> =
pTuple8()
/**
* [PTraversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight and ninth value of a [arrow.core.Tuple9]
*/
@JvmStatic
public fun <A, B> pTuple9(): PTraversal<Tuple9<A, A, A, A, A, A, A, A, A>, Tuple9<B, B, B, B, B, B, B, B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
get3 = { it.third },
get4 = { it.fourth },
get5 = { it.fifth },
get6 = { it.sixth },
get7 = { it.seventh },
get8 = { it.eighth },
get9 = { it.ninth },
set = { a, b, c, d, e, f, g, h, i, _ -> Tuple9(a, b, c, d, e, f, g, h, i) }
)
/**
* [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight and ninth value of a [arrow.core.Tuple9]
*/
@JvmStatic
public fun <A> tuple9(): Traversal<Tuple9<A, A, A, A, A, A, A, A, A>, A> =
pTuple9()
/**
* [PTraversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight, ninth and tenth value of a [arrow.core.Tuple10]
*/
@JvmStatic
public fun <A, B> pTuple10(): PTraversal<Tuple10<A, A, A, A, A, A, A, A, A, A>, Tuple10<B, B, B, B, B, B, B, B, B, B>, A, B> =
PTraversal(
get1 = { it.first },
get2 = { it.second },
get3 = { it.third },
get4 = { it.fourth },
get5 = { it.fifth },
get6 = { it.sixth },
get7 = { it.seventh },
get8 = { it.eighth },
get9 = { it.ninth },
get10 = { it.tenth },
set = { a, b, c, d, e, f, g, h, i, j, _ -> Tuple10(a, b, c, d, e, f, g, h, i, j) }
)
/**
* [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight, ninth and tenth value of a [arrow.core.Tuple10]
*/
@JvmStatic
public fun <A> tuple10(): Traversal<Tuple10<A, A, A, A, A, A, A, A, A, A>, A> =
pTuple10()
}
/**
* DSL to compose [Traversal] with a [Lens] for a structure [S] to see all its foci [A]
*
* @receiver [Lens] with a focus in [S]
* @return [Traversal] with a focus in [A]
*/
public val <U, V> PLens<U, V, S, T>.every: PTraversal<U, V, A, B>
get() =
[email protected](this@PTraversal)
/**
* DSL to compose [Traversal] with a [Prism] for a structure [S] to see all its foci [A]
*
* @receiver [Prism] with a focus in [S]
* @return [Traversal] with a focus in [A]
*/
public val <U, V> PPrism<U, V, S, T>.every: PTraversal<U, V, A, B>
get() =
this.compose(this@PTraversal)
/**
* DSL to compose [Traversal] with a [Optional] for a structure [S] to see all its foci [A]
*
* @receiver [Optional] with a focus in [S]
* @return [Traversal] with a focus in [A]
*/
public val <U, V> POptional<U, V, S, T>.every: PTraversal<U, V, A, B>
get() =
this.compose(this@PTraversal)
/**
* DSL to compose [Traversal] with a [Traversal] for a structure [S] to see all its foci [A]
*
* @receiver [Traversal] with a focus in [S]
* @return [Traversal] with a focus in [A]
*/
public val <U, V> PTraversal<U, V, S, T>.every: PTraversal<U, V, A, B>
get() =
this.compose(this@PTraversal)
}