@@ -153,11 +153,11 @@ public typealias Nel<A> = NonEmptyList<A>
153
153
*
154
154
*/
155
155
@JvmInline
156
- public value class NonEmptyList <out A > @PublishedApi internal constructor(
157
- public val all : List <A >
158
- ) : List<A > by all, NonEmptyCollection<A > {
156
+ public value class NonEmptyList <out E > @PublishedApi internal constructor(
157
+ public val all : List <E >
158
+ ) : List<E > by all, NonEmptyCollection<E > {
159
159
160
- public constructor (head: A , tail: List <A >): this (listOf (head) + tail)
160
+ public constructor (head: E , tail: List <E >): this (listOf (head) + tail)
161
161
162
162
@Suppress(" RESERVED_MEMBER_INSIDE_VALUE_CLASS" )
163
163
override fun equals (other : Any? ): Boolean = when (other) {
@@ -170,56 +170,56 @@ public value class NonEmptyList<out A> @PublishedApi internal constructor(
170
170
171
171
override fun isEmpty (): Boolean = false
172
172
173
- public fun toList (): List <A > = all
173
+ public fun toList (): List <E > = all
174
174
175
- public override val head: A
175
+ public override val head: E
176
176
get() = all.first()
177
177
178
- public val tail: List <A >
178
+ public val tail: List <E >
179
179
get() = all.drop(1 )
180
180
181
- override fun lastOrNull (): A = when {
181
+ override fun lastOrNull (): E = when {
182
182
tail.isNotEmpty() -> tail.last()
183
183
else -> head
184
184
}
185
185
186
186
@Suppress(" OVERRIDE_BY_INLINE" , " NOTHING_TO_INLINE" )
187
- public override inline fun distinct (): NonEmptyList <A > =
187
+ public override inline fun distinct (): NonEmptyList <E > =
188
188
NonEmptyList (all.distinct())
189
189
190
190
@Suppress(" OVERRIDE_BY_INLINE" )
191
- public override inline fun <K > distinctBy (selector : (A ) -> K ): NonEmptyList <A > =
191
+ public override inline fun <K > distinctBy (selector : (E ) -> K ): NonEmptyList <E > =
192
192
NonEmptyList (all.distinctBy(selector))
193
193
194
194
@Suppress(" OVERRIDE_BY_INLINE" )
195
- public override inline fun <B > map (transform : (A ) -> B ): NonEmptyList <B > =
195
+ public override inline fun <T > map (transform : (E ) -> T ): NonEmptyList <T > =
196
196
NonEmptyList (all.map(transform))
197
197
198
198
@Suppress(" OVERRIDE_BY_INLINE" )
199
- public override inline fun <B > flatMap (transform : (A ) -> NonEmptyCollection <B >): NonEmptyList <B > =
199
+ public override inline fun <T > flatMap (transform : (E ) -> NonEmptyCollection <T >): NonEmptyList <T > =
200
200
NonEmptyList (all.flatMap(transform))
201
201
202
202
@Suppress(" OVERRIDE_BY_INLINE" )
203
- public override inline fun <B > mapIndexed (transform : (index: Int , A ) -> B ): NonEmptyList <B > =
203
+ public override inline fun <T > mapIndexed (transform : (index: Int , E ) -> T ): NonEmptyList <T > =
204
204
NonEmptyList (transform(0 , head), tail.mapIndexed { ix, e -> transform(ix + 1 , e) })
205
205
206
- public operator fun plus (l : NonEmptyList <@UnsafeVariance A >): NonEmptyList <A > =
206
+ public operator fun plus (l : NonEmptyList <@UnsafeVariance E >): NonEmptyList <E > =
207
207
this + l.all
208
208
209
- public override operator fun plus (elements : Iterable <@UnsafeVariance A >): NonEmptyList <A > =
209
+ public override operator fun plus (elements : Iterable <@UnsafeVariance E >): NonEmptyList <E > =
210
210
NonEmptyList (all + elements)
211
211
212
- public override operator fun plus (element : @UnsafeVariance A ): NonEmptyList <A > =
212
+ public override operator fun plus (element : @UnsafeVariance E ): NonEmptyList <E > =
213
213
NonEmptyList (all + element)
214
214
215
- public inline fun <B > foldLeft (b : B , f : (B , A ) -> B ): B {
215
+ public inline fun <Acc > foldLeft (b : Acc , f : (Acc , E ) -> Acc ): Acc {
216
216
contract { callsInPlace(f, InvocationKind .AT_LEAST_ONCE ) }
217
217
var accumulator = f(b, head)
218
218
for (element in tail) accumulator = f(accumulator, element)
219
219
return accumulator
220
220
}
221
221
222
- public inline fun <B > coflatMap (f : (NonEmptyList <A >) -> B ): NonEmptyList <B > {
222
+ public inline fun <T > coflatMap (f : (NonEmptyList <E >) -> T ): NonEmptyList <T > {
223
223
contract { callsInPlace(f, InvocationKind .AT_LEAST_ONCE ) }
224
224
var current = this
225
225
return buildList {
@@ -230,19 +230,19 @@ public value class NonEmptyList<out A> @PublishedApi internal constructor(
230
230
}.let (::NonEmptyList )
231
231
}
232
232
233
- public fun extract (): A =
233
+ public fun extract (): E =
234
234
this .head
235
235
236
236
override fun toString (): String =
237
237
" NonEmptyList(${all.joinToString()} )"
238
238
239
- public fun <B > align (b : NonEmptyList <B >): NonEmptyList <Ior <A , B >> =
240
- NonEmptyList (all.align(b ))
239
+ public fun <T > align (other : NonEmptyList <T >): NonEmptyList <Ior <E , T >> =
240
+ NonEmptyList (all.align(other ))
241
241
242
- public fun <B > padZip (other : NonEmptyList <B >): NonEmptyList <Pair <A ?, B ?>> =
242
+ public fun <T > padZip (other : NonEmptyList <T >): NonEmptyList <Pair <E ?, T ?>> =
243
243
padZip(other, { it to null }, { null to it }, { a, b -> a to b })
244
244
245
- public inline fun <B , C > padZip (other : NonEmptyList <B >, left : (A ) -> C , right : (B ) -> C , both : (A , B ) -> C ): NonEmptyList <C > {
245
+ public inline fun <B , C > padZip (other : NonEmptyList <B >, left : (E ) -> C , right : (B ) -> C , both : (E , B ) -> C ): NonEmptyList <C > {
246
246
contract { callsInPlace(both, InvocationKind .AT_LEAST_ONCE ) }
247
247
return NonEmptyList (both(head, other.head), tail.padZip(other.tail, left, right) { a, b -> both(a, b) })
248
248
}
@@ -253,12 +253,12 @@ public value class NonEmptyList<out A> @PublishedApi internal constructor(
253
253
nonEmptyListOf(Unit )
254
254
}
255
255
256
- public fun <B > zip (fb : NonEmptyList <B >): NonEmptyList <Pair <A , B >> =
257
- zip(fb , ::Pair )
256
+ public fun <T > zip (other : NonEmptyList <T >): NonEmptyList <Pair <E , T >> =
257
+ zip(other , ::Pair )
258
258
259
259
public inline fun <B , Z > zip (
260
260
b : NonEmptyList <B >,
261
- map : (A , B ) -> Z
261
+ map : (E , B ) -> Z
262
262
): NonEmptyList <Z > {
263
263
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
264
264
return NonEmptyList (map(head, b.head), tail.zip(b.tail) { a, bb -> map(a, bb) })
@@ -267,7 +267,7 @@ public value class NonEmptyList<out A> @PublishedApi internal constructor(
267
267
public inline fun <B , C , Z > zip (
268
268
b : NonEmptyList <B >,
269
269
c : NonEmptyList <C >,
270
- map : (A , B , C ) -> Z
270
+ map : (E , B , C ) -> Z
271
271
): NonEmptyList <Z > {
272
272
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
273
273
return NonEmptyList (map(head, b.head, c.head), tail.zip(b.tail, c.tail) { a, bb, cc -> map(a, bb, cc) })
@@ -277,152 +277,152 @@ public value class NonEmptyList<out A> @PublishedApi internal constructor(
277
277
b : NonEmptyList <B >,
278
278
c : NonEmptyList <C >,
279
279
d : NonEmptyList <D >,
280
- map : (A , B , C , D ) -> Z
280
+ map : (E , B , C , D ) -> Z
281
281
): NonEmptyList <Z > {
282
282
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
283
283
return NonEmptyList (map(head, b.head, c.head, d.head), tail.zip(b.tail, c.tail, d.tail) { a, bb, cc, dd -> map(a, bb, cc, dd) })
284
284
}
285
285
286
- public inline fun <B , C , D , E , Z > zip (
286
+ public inline fun <B , C , D , F , Z > zip (
287
287
b : NonEmptyList <B >,
288
288
c : NonEmptyList <C >,
289
289
d : NonEmptyList <D >,
290
- e : NonEmptyList <E >,
291
- map : (A , B , C , D , E ) -> Z
290
+ e : NonEmptyList <F >,
291
+ map : (E , B , C , D , F ) -> Z
292
292
): NonEmptyList <Z > {
293
293
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
294
294
return NonEmptyList (map(head, b.head, c.head, d.head, e.head), tail.zip(b.tail, c.tail, d.tail, e.tail) { a, bb, cc, dd, ee -> map(a, bb, cc, dd, ee) })
295
295
}
296
296
297
- public inline fun <B , C , D , E , F , Z > zip (
297
+ public inline fun <B , C , D , F , G , Z > zip (
298
298
b : NonEmptyList <B >,
299
299
c : NonEmptyList <C >,
300
300
d : NonEmptyList <D >,
301
- e : NonEmptyList <E >,
302
- f : NonEmptyList <F >,
303
- map : (A , B , C , D , E , F ) -> Z
301
+ e : NonEmptyList <F >,
302
+ f : NonEmptyList <G >,
303
+ map : (E , B , C , D , F , G ) -> Z
304
304
): NonEmptyList <Z > {
305
305
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
306
306
return NonEmptyList (map(head, b.head, c.head, d.head, e.head, f.head), tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail) { a, bb, cc, dd, ee, ff -> map(a, bb, cc, dd, ee, ff) })
307
307
}
308
308
309
- public inline fun <B , C , D , E , F , G , Z > zip (
309
+ public inline fun <B , C , D , F , G , H , Z > zip (
310
310
b : NonEmptyList <B >,
311
311
c : NonEmptyList <C >,
312
312
d : NonEmptyList <D >,
313
- e : NonEmptyList <E >,
314
- f : NonEmptyList <F >,
315
- g : NonEmptyList <G >,
316
- map : (A , B , C , D , E , F , G ) -> Z
313
+ e : NonEmptyList <F >,
314
+ f : NonEmptyList <G >,
315
+ g : NonEmptyList <H >,
316
+ map : (E , B , C , D , F , G , H ) -> Z
317
317
): NonEmptyList <Z > {
318
318
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
319
319
return NonEmptyList (map(head, b.head, c.head, d.head, e.head, f.head, g.head), tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail) { a, bb, cc, dd, ee, ff, gg -> map(a, bb, cc, dd, ee, ff, gg) })
320
320
}
321
321
322
- public inline fun <B , C , D , E , F , G , H , Z > zip (
322
+ public inline fun <B , C , D , F , G , H , I , Z > zip (
323
323
b : NonEmptyList <B >,
324
324
c : NonEmptyList <C >,
325
325
d : NonEmptyList <D >,
326
- e : NonEmptyList <E >,
327
- f : NonEmptyList <F >,
328
- g : NonEmptyList <G >,
329
- h : NonEmptyList <H >,
330
- map : (A , B , C , D , E , F , G , H ) -> Z
326
+ e : NonEmptyList <F >,
327
+ f : NonEmptyList <G >,
328
+ g : NonEmptyList <H >,
329
+ h : NonEmptyList <I >,
330
+ map : (E , B , C , D , F , G , H , I ) -> Z
331
331
): NonEmptyList <Z > {
332
332
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
333
333
return NonEmptyList (map(head, b.head, c.head, d.head, e.head, f.head, g.head, h.head), tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail, h.tail) { a, bb, cc, dd, ee, ff, gg, hh -> map(a, bb, cc, dd, ee, ff, gg, hh) })
334
334
}
335
335
336
- public inline fun <B , C , D , E , F , G , H , I , Z > zip (
336
+ public inline fun <B , C , D , F , G , H , I , J , Z > zip (
337
337
b : NonEmptyList <B >,
338
338
c : NonEmptyList <C >,
339
339
d : NonEmptyList <D >,
340
- e : NonEmptyList <E >,
341
- f : NonEmptyList <F >,
342
- g : NonEmptyList <G >,
343
- h : NonEmptyList <H >,
344
- i : NonEmptyList <I >,
345
- map : (A , B , C , D , E , F , G , H , I ) -> Z
340
+ e : NonEmptyList <F >,
341
+ f : NonEmptyList <G >,
342
+ g : NonEmptyList <H >,
343
+ h : NonEmptyList <I >,
344
+ i : NonEmptyList <J >,
345
+ map : (E , B , C , D , F , G , H , I , J ) -> Z
346
346
): NonEmptyList <Z > {
347
347
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
348
348
return NonEmptyList (map(head, b.head, c.head, d.head, e.head, f.head, g.head, h.head, i.head), tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail, h.tail, i.tail) { a, bb, cc, dd, ee, ff, gg, hh, ii -> map(a, bb, cc, dd, ee, ff, gg, hh, ii) })
349
349
}
350
350
351
- public inline fun <B , C , D , E , F , G , H , I , J , Z > zip (
351
+ public inline fun <B , C , D , F , G , H , I , J , K , Z > zip (
352
352
b : NonEmptyList <B >,
353
353
c : NonEmptyList <C >,
354
354
d : NonEmptyList <D >,
355
- e : NonEmptyList <E >,
356
- f : NonEmptyList <F >,
357
- g : NonEmptyList <G >,
358
- h : NonEmptyList <H >,
359
- i : NonEmptyList <I >,
360
- j : NonEmptyList <J >,
361
- map : (A , B , C , D , E , F , G , H , I , J ) -> Z
355
+ e : NonEmptyList <F >,
356
+ f : NonEmptyList <G >,
357
+ g : NonEmptyList <H >,
358
+ h : NonEmptyList <I >,
359
+ i : NonEmptyList <J >,
360
+ j : NonEmptyList <K >,
361
+ map : (E , B , C , D , F , G , H , I , J , K ) -> Z
362
362
): NonEmptyList <Z > {
363
363
contract { callsInPlace(map, InvocationKind .AT_LEAST_ONCE ) }
364
364
return NonEmptyList (map(head, b.head, c.head, d.head, e.head, f.head, g.head, h.head, i.head, j.head), tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail, h.tail, i.tail, j.tail) { a, bb, cc, dd, ee, ff, gg, hh, ii, jj -> map(a, bb, cc, dd, ee, ff, gg, hh, ii, jj) })
365
365
}
366
366
}
367
367
368
368
@JvmName(" nonEmptyListOf" )
369
- public fun <A > nonEmptyListOf (head : A , vararg t : A ): NonEmptyList <A > =
369
+ public fun <E > nonEmptyListOf (head : E , vararg t : E ): NonEmptyList <E > =
370
370
NonEmptyList (listOf (head) + t)
371
371
372
372
@JvmName(" nel" )
373
373
@Suppress(" NOTHING_TO_INLINE" )
374
- public inline fun <A > A .nel (): NonEmptyList <A > =
374
+ public inline fun <E > E .nel (): NonEmptyList <E > =
375
375
NonEmptyList (listOf (this ))
376
376
377
- public operator fun <A : Comparable <A >> NonEmptyList<A >.compareTo (other : NonEmptyList <A >): Int =
377
+ public operator fun <E : Comparable <E >> NonEmptyList<E >.compareTo (other : NonEmptyList <E >): Int =
378
378
all.compareTo(other.all)
379
379
380
- public fun <A > NonEmptyList<NonEmptyList<A >>.flatten (): NonEmptyList <A > =
380
+ public fun <E > NonEmptyList<NonEmptyList<E >>.flatten (): NonEmptyList <E > =
381
381
this .flatMap(::identity)
382
382
383
- public inline fun <A , B : Comparable <B >> NonEmptyList<A >.minBy (selector : (A ) -> B ): A =
383
+ public inline fun <E , T : Comparable <T >> NonEmptyList<E >.minBy (selector : (E ) -> T ): E =
384
384
minByOrNull(selector)!!
385
385
386
- public inline fun <A , B : Comparable <B >> NonEmptyList<A >.maxBy (selector : (A ) -> B ): A =
386
+ public inline fun <E , T : Comparable <T >> NonEmptyList<E >.maxBy (selector : (E ) -> T ): E =
387
387
maxByOrNull(selector)!!
388
388
389
389
@Suppress(" NOTHING_TO_INLINE" )
390
- public inline fun <T : Comparable <T >> NonEmptyList<T >.min (): T =
390
+ public inline fun <E : Comparable <E >> NonEmptyList<E >.min (): E =
391
391
minOrNull()!!
392
392
393
393
@Suppress(" NOTHING_TO_INLINE" )
394
- public inline fun <T : Comparable <T >> NonEmptyList<T >.max (): T =
394
+ public inline fun <E : Comparable <E >> NonEmptyList<E >.max (): E =
395
395
maxOrNull()!!
396
396
397
397
public fun <A , B > NonEmptyList <Pair <A , B >>.unzip (): Pair <NonEmptyList <A >, NonEmptyList<B>> =
398
398
this .unzip(::identity)
399
399
400
400
@Suppress(" WRONG_INVOCATION_KIND" )
401
- public inline fun <A , B , C > NonEmptyList<C >.unzip (f : (C ) -> Pair <A , B >): Pair <NonEmptyList <A >, NonEmptyList<B>> {
401
+ public inline fun <A , B , E > NonEmptyList<E >.unzip (f : (E ) -> Pair <A , B >): Pair <NonEmptyList <A >, NonEmptyList<B>> {
402
402
contract { callsInPlace(f, InvocationKind .AT_LEAST_ONCE ) }
403
403
return map { f(it) }.stdlibUnzip().let { (l1, l2) ->
404
404
l1.toNonEmptyListOrNull()!! to l2.toNonEmptyListOrNull()!!
405
405
}
406
406
}
407
407
408
- public inline fun <E , A , B > NonEmptyList<A >.mapOrAccumulate (
409
- combine : (E , E ) -> E ,
410
- @BuilderInference transform : RaiseAccumulate <E >.(A ) -> B
411
- ): Either <E , NonEmptyList <B >> =
408
+ public inline fun <Error , E , T > NonEmptyList<E >.mapOrAccumulate (
409
+ combine : (Error , Error ) -> Error ,
410
+ @BuilderInference transform : RaiseAccumulate <Error >.(E ) -> T
411
+ ): Either <Error , NonEmptyList <T >> =
412
412
all.mapOrAccumulate(combine, transform).map { requireNotNull(it.toNonEmptyListOrNull()) }
413
413
414
- public inline fun <E , A , B > NonEmptyList<A >.mapOrAccumulate (
415
- @BuilderInference transform : RaiseAccumulate <E >.(A ) -> B
416
- ): Either <NonEmptyList <E >, NonEmptyList<B >> =
414
+ public inline fun <Error , E , T > NonEmptyList<E >.mapOrAccumulate (
415
+ @BuilderInference transform : RaiseAccumulate <Error >.(E ) -> T
416
+ ): Either <NonEmptyList <Error >, NonEmptyList<T >> =
417
417
all.mapOrAccumulate(transform).map { requireNotNull(it.toNonEmptyListOrNull()) }
418
418
419
419
@JvmName(" toNonEmptyListOrNull" )
420
- public fun <A > Iterable<A >.toNonEmptyListOrNull (): NonEmptyList <A >? {
420
+ public fun <T > Iterable<T >.toNonEmptyListOrNull (): NonEmptyList <T >? {
421
421
val iter = iterator()
422
422
if (! iter.hasNext()) return null
423
423
return NonEmptyList (iter.next(), Iterable { iter }.toList())
424
424
}
425
425
426
426
@JvmName(" toNonEmptyListOrNone" )
427
- public fun <A > Iterable<A >.toNonEmptyListOrNone (): Option <NonEmptyList <A >> =
427
+ public fun <T > Iterable<T >.toNonEmptyListOrNone (): Option <NonEmptyList <T >> =
428
428
toNonEmptyListOrNull().toOption()
0 commit comments