You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Returns a [NotEmptyList] containing all the elements of this collection, or * returns `null` if this collection is [empty][Collection.isEmpty]. * * Here's some usage examples: * * ```kotlin * var collection: Collection<Int> = listOf(1, 2, 3) * var result: NotEmptyList<Int>? = collection.toNotEmptyListOrNull() * println(result) // [1, 2, 3] * * collection = emptyList() * result = collection.toNotEmptyListOrNull() * println(result) // null * ``` * * Please note that changes made to the original collection will not be * reflected on the resulting [NotEmptyList]. * * ```kotlin * val original: MutableCollection<Int> = mutableListOf(1, 2, 3) * val notEmptyList: NotEmptyList<Int>? = original.toNotEmptyListOrNull() * println(original) // [1, 2, 3] * println(notEmptyList) // [1, 2, 3] * * original.clear() * println(original) // [] * println(notEmptyList) // [1, 2, 3] * ``` * * You can use the [toNotEmptyListOrThrow] function for throwing an * [IllegalArgumentException] instead of returning `null` when this collection * is [empty][Collection.isEmpty].*/
@ExperimentalCollectionApi
@ExperimentalSinceKotoolsTypes("4.3.1")
publicfun <E> Collection<E>.toNotEmptyListOrNull(): NotEmptyList<E>? {
TODO()
}
/** * Returns a [NotEmptyList] containing all the elements of this collection, or * throws an [IllegalArgumentException] if this collection is * [empty][Collection.isEmpty]. * * Here's some usage examples: * * ```kotlin * var collection: Collection<Int> = listOf(1, 2, 3) * var result: NotEmptyList<Int> = collection.toNotEmptyListOrThrow() * println(result) // [1, 2, 3] * * collection = emptyList() * collection.toNotEmptyListOrThrow() // IllegalArgumentException * ``` * * Please note that changes made to the original collection will not be * reflected on the resulting [NotEmptyList]. * * ```kotlin * val original: MutableCollection<Int> = mutableListOf(1, 2, 3) * val notEmptyList: NotEmptyList<Int> = original.toNotEmptyListOrThrow() * println(original) // [1, 2, 3] * println(notEmptyList) // [1, 2, 3] * * original.clear() * println(original) // [] * println(notEmptyList) // [1, 2, 3] * ``` * * You can use the [toNotEmptyListOrNull] function for returning `null` instead * of throwing an [IllegalArgumentException] when this collection is * [empty][Collection.isEmpty].*/
@ExperimentalCollectionApi
@ExperimentalSinceKotoolsTypes("4.3.1")
publicfun <E> Collection<E>.toNotEmptyListOrThrow(): NotEmptyList<E> {
TODO()
}
Check your changes in the generated documentation.
### Added**Experimental** builders suffixed by `OrNull` and `OrThrow` for the following
types:
-`NotEmptyList` (issue [#176] implemented by [@YourGitHubProfile](#)).
[#176]: https://github.com/kotools/types/issues/176
Commit your local changes by running the git commit -a command in your terminal with the message below.
Commit message
feat(#176): add experimental builders for 'NotEmptyList'
New builders: 'toNotEmptyListOrNull' and 'toNotEmptyListOrThrow'.
These are not implemented yet.
Implement the toNotEmptyListOrThrow function by resolving the following tasks:
Refactor the construction of the type by using functional programming tools provided by Kotlin for improving its readability, composability and performance.
The text was updated successfully, but these errors were encountered:
LVMVRQUXL
changed the title
New builders suffixed by OrNull and OrThrow for NotEmptyList
New type converters suffixed by OrNull and OrThrow for NotEmptyListOct 22, 2023
Description
Like discussed in #104, we would like to introduce experimental builders for the
NotEmptyList
type that should:null
in case of a failure if the builder is suffixed byOrNull
IllegalArgumentException
in case of a failure if the builder is suffixed byOrThrow
.These builders should work on all platforms and should be declared in the
NotEmptyList.kt
file after thetoNotEmptyList
function.Their tests should be declared in the
NotEmptyListTest
class after thecollection_toNotEmptyList_should_fail_with_an_empty_Collection
function.Dependencies
This issue is blocked by the following ones:
ExperimentalCollectionApi
annotation #177Checklist
NotEmptyList.kt
file.Function signatures
Unreleased
section in the CHANGELOG, replacing theYourGitHubProfile
placeholder by your GitHub profile (see an example here).Entry in changelog
git commit -a
command in your terminal with the message below.Commit message
toNotEmptyListOrThrow
function by resolving the following tasks:git commit -a
command in your terminal with the message below.Commit message
toNotEmptyListOrNull
function by resolving the following tasks:git commit -a
command in your terminal with the message below.Commit message
Maintainers only
The text was updated successfully, but these errors were encountered: