Skip to content

Commit

Permalink
docs(#137): improve documentation of NotEmptySet.toSet function
Browse files Browse the repository at this point in the history
  • Loading branch information
LVMVRQUXL committed Jul 27, 2023
1 parent 8c54262 commit 1cd8f74
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/commonMain/kotlin/kotools/types/collection/NotEmptySet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,18 @@ public value class NotEmptySet<out E> private constructor(
?: setOf(head)
)

/** Returns all elements of this set as a [Set] of type [E]. */
/**
* Returns all elements of this set as a [Set] of type [E].
*
* ```kotlin
* import kotools.types.collection.NotEmptySet
* import kotools.types.collection.notEmptySetOf
*
* val notEmptySet: NotEmptySet<Int> = notEmptySetOf(1, 2, 3, 1)
* val set: Set<Int> = notEmptySet.toSet()
* println(set) // [1, 2, 3]
* ```
*/
public fun toSet(): Set<E> {
val elements: Set<E> = setOf(head)
return tail?.let { elements + it.toSet() } ?: elements
Expand Down

0 comments on commit 1cd8f74

Please sign in to comment.