@@ -4,7 +4,7 @@ import kotlin.jvm.JvmInline
4
4
5
5
@JvmInline
6
6
public value class NonEmptySet <out A > private constructor(
7
- private val elements : Set <A >
7
+ @PublishedApi internal val elements : Set <A >
8
8
) : Set<A> by elements, NonEmptyCollection<A> {
9
9
10
10
public constructor (first: A , rest: Set <A >) : this (setOf (first) + rest)
@@ -21,6 +21,25 @@ public value class NonEmptySet<out A> private constructor(
21
21
22
22
override fun lastOrNull (): A = elements.last()
23
23
24
+ @Suppress(" OVERRIDE_BY_INLINE" )
25
+ public override inline fun <B > map (transform : (A ) -> B ): NonEmptyList <B > =
26
+ elements.map(transform).toNonEmptyListOrNull()!!
27
+
28
+ @Suppress(" OVERRIDE_BY_INLINE" )
29
+ public override inline fun <B > mapIndexed (transform : (index: Int , A ) -> B ): NonEmptyList <B > =
30
+ elements.mapIndexed(transform).toNonEmptyListOrNull()!!
31
+
32
+ @Suppress(" OVERRIDE_BY_INLINE" )
33
+ public override inline fun <B > flatMap (transform : (A ) -> NonEmptyCollection <B >): NonEmptyList <B > =
34
+ elements.flatMap(transform).toNonEmptyListOrNull()!!
35
+
36
+ override fun distinct (): NonEmptyList <A > =
37
+ toNonEmptyList()
38
+
39
+ @Suppress(" OVERRIDE_BY_INLINE" )
40
+ public override inline fun <K > distinctBy (selector : (A ) -> K ): NonEmptyList <A > =
41
+ elements.distinctBy(selector).toNonEmptyListOrNull()!!
42
+
24
43
override fun toString (): String = " NonEmptySet(${this .joinToString()} )"
25
44
26
45
@Suppress(" RESERVED_MEMBER_INSIDE_VALUE_CLASS" )
0 commit comments