This repository has been archived by the owner on Feb 24, 2021. It is now read-only.
/
ListK.kt
601 lines (552 loc) · 18.6 KB
/
ListK.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
package arrow.core
import arrow.Kind
import arrow.typeclasses.Applicative
import arrow.typeclasses.Show
import arrow.typeclasses.ShowDeprecation
class ForListK private constructor() {
companion object
}
typealias ListKOf<A> = arrow.Kind<ForListK, A>
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
inline fun <A> ListKOf<A>.fix(): ListK<A> =
this as ListK<A>
/**
*
* ListK wraps over the platform `List` type to make it a [type constructor]({{'/patterns/glossary/#type-constructors' | relative_url }}).
*
* It can be created from Kotlin List type with a convenient `k()` function.
*
* ```kotlin:ank:playground
* import arrow.core.k
*
* val value =
* //sampleStart
* listOf(1, 2, 3).k()
* //sampleEnd
* fun main() {
* println(value)
* }
* ```
*
* For most use cases you will never use `ListK` directly but `List` directly with the extension functions that Arrow projects over it.
*
* ListK implements operators from many useful typeclasses.
*
* The @extension type class processor expands all type class combinators that `ListK` provides automatically over `List`
*
* For instance, it has `combineK` from the [SemigroupK]({{'/arrow/typeclasses/semigroupk/' | relative_url }}) typeclass.
*
* It can be used to cheaply combine two lists:
*
* ```kotlin:ank:playground
* import arrow.core.extensions.list.semigroupK.combineK
*
* //sampleStart
* val hello = listOf('h', 'e', 'l', 'l', 'o')
* val commaSpace = listOf(',', ' ')
* val world = listOf('w', 'o', 'r', 'l', 'd')
*
* val combinedList = hello.combineK(commaSpace).combineK(world)
* //sampleEnd
* fun main() {
* println("combinedList = $combinedList")
* }
* ```
*
* The functions `traverse` and `sequence` come from [Traverse]({{'/apidocs/arrow-core-data/arrow.typeclasses/-traverse/' | relative_url }}).
*
* Traversing a list creates a new container [Kind<F, A>]({{'/patterns/glossary/#type-constructors' | relative_url }}) by combining the result of a function applied to each element:
*
* ```kotlin:ank:playground
* import arrow.core.None
* import arrow.core.Option
* import arrow.core.Some
* import arrow.core.extensions.list.traverse.traverse
* import arrow.core.extensions.option.applicative.applicative
*
* //sampleStart
* val numbers = listOf(Math.random(), Math.random(), Math.random())
* val traversedList = numbers.traverse(Option.applicative(), { if (it > 0.5) Some(it) else None })
* //sampleEnd
* fun main() {
* println("traversedList $traversedList")
* }
* ```
*
* and complements the convenient function `sequence()` that converts a list of `ListK<Kind<F, A>>` into a `Kind<F, ListK<A>>`:
*
* ```kotlin:ank:playground
* import arrow.core.Option
* import arrow.core.Some
* import arrow.core.extensions.list.traverse.sequence
* import arrow.core.extensions.option.applicative.applicative
*
* //sampleStart
* val requests = listOf(Some(Math.random()), Some(Math.random()), Some(Math.random()))
* val sequenceList = requests.sequence(Option.applicative())
* //sampleEnd
* fun main() {
* println("sequenceList = $sequenceList")
* }
* ```
*
* If you want to aggregate the elements of a list into any other value you can use `foldLeft` and `foldRight` from [Foldable]({{'/arrow/typeclasses/foldable' | relative_url }}).
*
* Folding a list into a new value, `String` in this case, starting with an initial value and a combine function:
*
* ```kotlin:ank:playground
* import arrow.core.k
* import arrow.core.extensions.list.foldable.foldLeft
* val value =
* //sampleStart
* listOf('a', 'b', 'c', 'd', 'e').k().foldLeft("-> ") { x, y -> x + y }
* //sampleEnd
* fun main() {
* println(value)
* }
* ```
*
* Or you can apply a list of transformations using `ap` from [Applicative]({{'/arrow/typeclasses/applicative/' | relative_url }}).
*
* ```kotlin:ank:playground
* import arrow.core.extensions.list.apply.ap
*
* val value =
* //sampleStart
* listOf(1, 2, 3).ap(listOf({ x: Int -> x + 10 }, { x: Int -> x * 2 }))
* //sampleEnd
* fun main() {
* println(value)
* }
* ```
*
*/
data class ListK<out A>(private val list: List<A>) : ListKOf<A>, List<A> by list {
fun <B> flatMap(f: (A) -> ListKOf<B>): ListK<B> = list.flatMap { f(it).fix().list }.k()
fun <B> map(f: (A) -> B): ListK<B> = list.map(f).k()
fun <B> foldLeft(b: B, f: (B, A) -> B): B = fold(b, f)
fun <B> foldRight(lb: Eval<B>, f: (A, Eval<B>) -> Eval<B>): Eval<B> {
fun loop(fa_p: ListK<A>): Eval<B> = when {
fa_p.list.isEmpty() -> lb
else -> f(fa_p.fix().list.first(), Eval.defer { loop(fa_p.list.drop(1).k()) })
}
return Eval.defer { loop(this) }
}
override fun equals(other: Any?): Boolean =
when (other) {
is ListK<*> -> this.list == other.list
is List<*> -> this.list == other
else -> false
}
fun <B> ap(ff: ListKOf<(A) -> B>): ListK<B> = flatMap { a -> ff.fix().map { f -> f(a) } }
fun <G, B> traverse(GA: Applicative<G>, f: (A) -> Kind<G, B>): Kind<G, ListK<B>> =
foldRight(Eval.now(GA.just(emptyList<B>().k()))) { a, eval ->
GA.run { f(a).apEval(eval.map { it.map { xs -> { a: B -> (listOf(a) + xs).k() } } }) }
}.value()
fun <B, Z> map2(fb: ListKOf<B>, f: (Tuple2<A, B>) -> Z): ListK<Z> =
flatMap { a ->
fb.fix().map { b ->
f(Tuple2(a, b))
}
}
@Deprecated("Deprecated, use mapNotNull(f: (A) -> B?) instead", ReplaceWith("mapNotNull(f: (A) -> B?)"))
fun <B> filterMap(f: (A) -> Option<B>): ListK<B> =
flatMap { a -> f(a).fold({ empty<B>() }, { just(it) }) }
/**
* Returns a [ListK] containing the transformed values from the original
* [ListK] filtering out any null value.
*
* Example:
* ```kotlin:ank:playground
* import arrow.core.*
*
* //sampleStart
* val evenStrings = listOf(1, 2).k().mapNotNull {
* when (it % 2 == 0) {
* true -> it.toString()
* else -> null
* }
* }
* //sampleEnd
*
* fun main() {
* println("evenStrings = $evenStrings")
* }
* ```
*/
fun <B> mapNotNull(f: (A) -> B?): ListK<B> =
flatMap { a -> f(a)?.let { just(it) } ?: empty<B>() }
override fun hashCode(): Int = list.hashCode()
/**
* Align two Lists as in zip, but filling in blanks with None.
*/
@Deprecated("Deprecated, use `padZipWithNull` instead", ReplaceWith("padZipWithNull(other: ListK<B>)"))
fun <B> padZip(
other: ListK<B>
): ListK<Tuple2<Option<A>, Option<B>>> =
alignWith(this, other) { ior ->
ior.fold(
{ it.some() toT Option.empty<B>() },
{ Option.empty<A>() toT it.some() },
{ a, b -> a.some() toT b.some() }
)
}
/**
* Returns a [ListK<Tuple2<A?, B?>>] containing the zipped values of the two listKs
* with null for padding.
*
* Example:
* ```kotlin:ank:playground
* import arrow.core.*
*
* //sampleStart
* val padRight = listOf(1, 2).k().padZip(listOf("a").k()) // Result: ListK(Tuple2(1, "a"), Tuple2(2, null))
* val padLeft = listOf(1).k().padZip(listOf("a", "b").k()) // Result: ListK(Tuple2(1, "a"), Tuple2(null, "b"))
* val noPadding = listOf(1, 2).k().padZip(listOf("a", "b").k()) // Result: ListK(Tuple2(1, "a"), Tuple2(2, "b"))
* //sampleEnd
*
* fun main() {
* println("padRight = $padRight")
* println("padLeft = $padLeft")
* println("noPadding = $noPadding")
* }
* ```
*/
fun <B> padZipWithNull(
other: ListK<B>
): ListK<Tuple2<A?, B?>> =
alignWith(this, other) { ior ->
ior.fold(
{ it toT null },
{ null toT it },
{ a, b -> a toT b }
)
}
/**
* Align two Lists as in zipWith, but filling in blanks with None.
*/
@Deprecated("Deprecated, use `padZip(other: ListK<B>, fa: (A?, B?) -> C)` instead", ReplaceWith("padZip(other: ListK<B>, fa: (A?, B?) -> C)"))
fun <B, C> padZipWith(
other: ListK<B>,
fa: (Option<A>, Option<B>) -> C
): ListK<C> =
padZip(other).map { fa(it.a, it.b) }
/**
* Returns a [ListK<C>] containing the result of applying some transformation `(A?, B?) -> C`
* on a zip.
*
* Example:
* ```kotlin:ank:playground
* import arrow.core.*
*
* //sampleStart
* val padZipRight = listOf(1, 2).k().padZip(listOf("a").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"), Tuple2(2, null))
* val padZipLeft = listOf(1).k().padZip(listOf("a", "b").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"), Tuple2(null, "b"))
* val noPadding = listOf(1, 2).k().padZip(listOf("a", "b").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"), Tuple2(2, "b"))
* //sampleEnd
*
* fun main() {
* println("padZipRight = $padZipRight")
* println("padZipLeft = $padZipLeft")
* println("noPadding = $noPadding")
* }
* ```
*/
fun <B, C> padZip(
other: ListK<B>,
fa: (A?, B?) -> C
): ListK<C> =
padZipWithNull(other).map { fa(it.a, it.b) }
/**
* Left-padded zipWith.
*/
@Deprecated("Deprecated, use `leftPadZip(other: ListK<B>, fab: (A?, B) -> C)` instead", ReplaceWith("leftPadZip(other: ListK<B>, fab: (A?, B) -> C)"))
fun <B, C> lpadZipWith(
other: ListK<B>,
fab: (Option<A>, B) -> C
): ListK<C> =
padZipWith(other) { a: Option<A>, b -> b.map { fab(a, it) } }.filterMap(::identity)
/**
* Returns a [ListK<C>] containing the result of applying some transformation `(A?, B) -> C`
* on a zip, excluding all cases where the right value is null.
*
* Example:
* ```kotlin:ank:playground
* import arrow.core.*
*
* //sampleStart
* val left = listOf(1, 2).k().leftPadZip(listOf("a").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"))
* val right = listOf(1).k().leftPadZip(listOf("a", "b").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"), Tuple2(null, "b"))
* val both = listOf(1, 2).k().leftPadZip(listOf("a", "b").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"), Tuple2(2, "b"))
* //sampleEnd
*
* fun main() {
* println("left = $left")
* println("right = $right")
* println("both = $both")
* }
* ```
*/
fun <B, C> leftPadZip(
other: ListK<B>,
fab: (A?, B) -> C
): ListK<C> =
padZip(other) { a: A?, b: B? -> b?.let { fab(a, it) } }.mapNotNull(::identity)
/**
* Left-padded zip.
*/
@Deprecated("Deprecated, use `leftPadZip(other: ListK<B>)` instead", ReplaceWith("leftPadZip(other: ListK<B>)"))
fun <B> lpadZip(
other: ListK<B>
): ListK<Tuple2<Option<A>, B>> =
this.lpadZipWith(other) { a, b -> a toT b }
/**
* Returns a [ListK<Tuple2<A?, B>>] containing the zipped values of the two listKs
* with null for padding on the left.
*
* Example:
* ```kotlin:ank:playground
* import arrow.core.*
*
* //sampleStart
* val padRight = listOf(1, 2).k().leftPadZip(listOf("a").k()) // Result: ListK(Tuple2(1, "a"))
* val padLeft = listOf(1).k().leftPadZip(listOf("a", "b").k()) // Result: ListK(Tuple2(1, "a"), Tuple2(null, "b"))
* val noPadding = listOf(1, 2).k().leftPadZip(listOf("a", "b").k()) // Result: ListK(Tuple2(1, "a"), Tuple2(2, "b"))
* //sampleEnd
*
* fun main() {
* println("left = $left")
* println("right = $right")
* println("both = $both")
* }
* ```
*/
fun <B> leftPadZip(
other: ListK<B>
): ListK<Tuple2<A?, B>> =
this.leftPadZip(other) { a, b -> a toT b }
/**
* Right-padded zipWith.
*/
@Deprecated("Deprecated, use `rightPadZip(other: ListK<B>, fa: (A, B?) -> C)` instead", ReplaceWith("rightPadZip(other: ListK<B>, fa: (A, B?) -> C)"))
fun <B, C> rpadZipWith(
other: ListK<B>,
fa: (A, Option<B>) -> C
): ListK<C> =
other.lpadZipWith(this) { a, b -> fa(b, a) }
/**
* Returns a [ListK<C>] containing the result of applying some transformation `(A, B?) -> C`
* on a zip, excluding all cases where the left value is null.
*
* Example:
* ```kotlin:ank:playground
* import arrow.core.*
*
* //sampleStart
* val left = listOf(1, 2).k().rightPadZip(listOf("a").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"), Tuple2(null, "b"))
* val right = listOf(1).k().rightPadZip(listOf("a", "b").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"))
* val both = listOf(1, 2).k().rightPadZip(listOf("a", "b").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"), Tuple2(2, "b"))
* //sampleEnd
*
* fun main() {
* println("left = $left")
* println("right = $right")
* println("both = $both")
* }
* ```
*/
fun <B, C> rightPadZip(
other: ListK<B>,
fa: (A, B?) -> C
): ListK<C> =
other.leftPadZip(this) { a, b -> fa(b, a) }
/**
* Right-padded zip.
*/
@Deprecated("Deprecated, use `rightPadZip(other: ListK<B>)` instead", ReplaceWith("rightPadZip(other: ListK<B>)"))
fun <B> rpadZip(
other: ListK<B>
): ListK<Tuple2<A, Option<B>>> =
this.rpadZipWith(other) { a, b ->
a toT b
}
/**
* Returns a [ListK<Tuple2<A, B?>>] containing the zipped values of the two listKs
* with null for padding on the right.
*
* Example:
* ```kotlin:ank:playground
* import arrow.core.*
*
* //sampleStart
* val padRight = listOf(1, 2).k().rightPadZip(listOf("a").k()) // Result: ListK(Tuple2(1, "a"), Tuple2(2, null))
* val padLeft = listOf(1).k().rightPadZip(listOf("a", "b").k()) // Result: ListK(Tuple2(1, "a"))
* val noPadding = listOf(1, 2).k().rightPadZip(listOf("a", "b").k()) // Result: ListK(Tuple2(1, "a"), Tuple2(2, "b"))
* //sampleEnd
*
* fun main() {
* println("left = $left")
* println("right = $right")
* println("both = $both")
* }
* ```
*/
fun <B> rightPadZip(
other: ListK<B>
): ListK<Tuple2<A, B?>> =
this.rightPadZip(other) { a, b -> a toT b }
@Deprecated(ShowDeprecation)
fun show(SA: Show<A>): String = SA.run {
joinToString(prefix = "[", separator = ", ", postfix = "]") { it.show() }
}
override fun toString(): String =
list.toString()
companion object {
fun <A> just(a: A): ListK<A> = listOf(a).k()
fun <A> empty(): ListK<A> = emptyList<A>().k()
@Suppress("UNCHECKED_CAST")
private tailrec fun <A, B> go(
buf: ArrayList<B>,
f: (A) -> Kind<ForListK, Either<A, B>>,
v: ListK<Either<A, B>>
) {
if (!v.isEmpty()) {
val head: Either<A, B> = v.first()
when (head) {
is Either.Right -> {
buf += head.b
go(buf, f, v.drop(1).k())
}
is Either.Left -> go(buf, f, (f(head.a).fix() + v.drop(1)).k())
}
}
}
fun <A, B> tailRecM(a: A, f: (A) -> Kind<ForListK, Either<A, B>>): ListK<B> {
val buf = ArrayList<B>()
go(buf, f, f(a).fix())
return ListK(buf)
}
fun <A, B, C> alignWith(a: ListK<A>, b: ListK<B>, fa: (Ior<A, B>) -> C): ListK<C> = align(a, b).map(fa)
fun <A, B> align(a: ListK<A>, b: ListK<B>): ListK<Ior<A, B>> = alignRec(a, b).k()
private fun <X, Y> alignRec(ls: List<X>, rs: List<Y>): List<Ior<X, Y>> = when {
ls.isEmpty() -> rs.map { it.rightIor() }
rs.isEmpty() -> ls.map { it.leftIor() }
else -> listOf(Ior.Both(ls.first(), rs.first())) + alignRec(ls.drop(1), rs.drop(1))
}
inline fun <B, C, D> mapN(
b: Iterable<B>,
c: Iterable<C>,
map: (B, C) -> D
): List<D> =
mapN(b, c, unit, unit, unit, unit, unit, unit, unit, unit) { b, c, _, _, _, _, _, _, _, _ -> map(b, c) }
inline fun <B, C, D, E> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
map: (B, C, D) -> E
): List<E> =
mapN(b, c, d, unit, unit, unit, unit, unit, unit, unit) { b, c, d, _, _, _, _, _, _, _ -> map(b, c, d) }
inline fun <B, C, D, E, F> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
map: (B, C, D, E) -> F
): List<F> =
mapN(b, c, d, e, unit, unit, unit, unit, unit, unit) { b, c, d, e, _, _, _, _, _, _ -> map(b, c, d, e) }
inline fun <B, C, D, E, F, G> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
map: (B, C, D, E, F) -> G
): List<G> =
mapN(b, c, d, e, f, unit, unit, unit, unit, unit) { b, c, d, e, f, _, _, _, _, _ -> map(b, c, d, e, f) }
inline fun <B, C, D, E, F, G, H> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
map: (B, C, D, E, F, G) -> H
): List<H> =
mapN(b, c, d, e, f, g, unit, unit, unit, unit) { b, c, d, e, f, g, _, _, _, _ -> map(b, c, d, e, f, g) }
inline fun <B, C, D, E, F, G, H, I> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
h: Iterable<H>,
map: (B, C, D, E, F, G, H) -> I
): List<I> =
mapN(b, c, d, e, f, g, h, unit, unit, unit) { b, c, d, e, f, g, h, _, _, _ -> map(b, c, d, e, f, g, h) }
inline fun <B, C, D, E, F, G, H, I, J> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
h: Iterable<H>,
i: Iterable<I>,
map: (B, C, D, E, F, G, H, I) -> J
): List<J> =
mapN(b, c, d, e, f, g, h, i, unit, unit) { b, c, d, e, f, g, h, i, _, _ -> map(b, c, d, e, f, g, h, i) }
inline fun <B, C, D, E, F, G, H, I, J, K> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
h: Iterable<H>,
i: Iterable<I>,
j: Iterable<J>,
map: (B, C, D, E, F, G, H, I, J) -> K
): List<K> =
mapN(b, c, d, e, f, g, h, i, j, unit) { b, c, d, e, f, g, h, i, j, _ -> map(b, c, d, e, f, g, h, i, j) }
inline fun <B, C, D, E, F, G, H, I, J, K, L> mapN(
b: Iterable<B>,
c: Iterable<C>,
d: Iterable<D>,
e: Iterable<E>,
f: Iterable<F>,
g: Iterable<G>,
h: Iterable<H>,
i: Iterable<I>,
j: Iterable<J>,
k: Iterable<K>,
map: (B, C, D, E, F, G, H, I, J, K) -> L
): List<L> =
b.flatMap { bb ->
c.flatMap { cc ->
d.flatMap { dd ->
e.flatMap { ee ->
f.flatMap { ff ->
g.flatMap { gg ->
h.flatMap { hh ->
i.flatMap { ii ->
j.flatMap { jj ->
k.map { kk ->
map(bb, cc, dd, ee, ff, gg, hh, ii, jj, kk)
}
}
}
}
}
}
}
}
}
}
}
}
fun <A> ListKOf<A>.combineK(y: ListKOf<A>): ListK<A> =
(fix() + y.fix()).k()
fun <A> List<A>.k(): ListK<A> = ListK(this)
fun <A> listKOf(vararg elements: A): ListK<A> =
listOf(*elements).k()