Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New type converters suffixed by OrNull and OrThrow for NotEmptyList #176

Closed
21 tasks done
Tracked by #157
LVMVRQUXL opened this issue Aug 20, 2023 · 1 comment
Closed
21 tasks done
Tracked by #157
Assignees
Labels
common Item related to all platforms. feature New feature or request.
Milestone

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented Aug 20, 2023

Description

Like discussed in #104, we would like to introduce experimental builders for the NotEmptyList type that should:

  • return null in case of a failure if the builder is suffixed by OrNull
  • throw an IllegalArgumentException in case of a failure if the builder is suffixed by OrThrow.

These builders should work on all platforms and should be declared in the NotEmptyList.kt file after the toNotEmptyList function.
Their tests should be declared in the NotEmptyListTest class after the collection_toNotEmptyList_should_fail_with_an_empty_Collection function.

Dependencies

This issue is blocked by the following ones:

Checklist

Function signatures
/**
 * 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")
public fun <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")
public fun <E> Collection<E>.toNotEmptyListOrThrow(): NotEmptyList<E> {
    TODO()
}
Entry in changelog
### 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 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:
    • Add unit tests for this new function.
    • Run tests on the JVM platform. These should fail at this stage.
    • Implement this new function without changing its signature.
    • Run tests on the JVM platform. These should pass at this stage.
    • Commit your local changes by running the git commit -a command in your terminal with the message below.
Commit message
feat(#176): implement the 'toNotEmptyListOrThrow' function
  • Implement the toNotEmptyListOrNull function by resolving the following tasks:
    • Add unit tests for this new function.
    • Run tests on the JVM platform. These should fail at this stage.
    • Implement this new function without changing its signature.
    • Run tests on the JVM platform. These should pass at this stage.
    • Commit your local changes by running the git commit -a command in your terminal with the message below.
Commit message
feat(#176): implement the 'toNotEmptyListOrNull' function

Maintainers only

  • Refactor the construction of the type by using functional programming tools provided by Kotlin for improving its readability, composability and performance.
@LVMVRQUXL LVMVRQUXL added feature New feature or request. common Item related to all platforms. labels Aug 20, 2023
@LVMVRQUXL LVMVRQUXL added this to the 4.4.0 milestone Aug 20, 2023
@LVMVRQUXL LVMVRQUXL self-assigned this Aug 20, 2023
@LVMVRQUXL LVMVRQUXL added the good first issue Issues having enough details for new contributors to work on. label Aug 20, 2023
@LVMVRQUXL LVMVRQUXL removed their assignment Aug 20, 2023
@LVMVRQUXL LVMVRQUXL added good first issue Issues having enough details for new contributors to work on. and removed good first issue Issues having enough details for new contributors to work on. labels Sep 1, 2023
@LVMVRQUXL LVMVRQUXL modified the milestones: 4.4.0, 4.3.1 Sep 3, 2023
@LVMVRQUXL LVMVRQUXL added good first issue Issues having enough details for new contributors to work on. and removed good first issue Issues having enough details for new contributors to work on. labels Sep 4, 2023
@LVMVRQUXL LVMVRQUXL removed the good first issue Issues having enough details for new contributors to work on. label Sep 21, 2023
@LVMVRQUXL LVMVRQUXL self-assigned this Sep 21, 2023
LVMVRQUXL added a commit that referenced this issue Sep 21, 2023
New builders: 'toNotEmptyListOrNull' and 'toNotEmptyListOrThrow'.
These are not implemented yet.
@LVMVRQUXL
Copy link
Contributor Author

Done.

LVMVRQUXL added a commit that referenced this issue Sep 21, 2023
New builders: 'toNotEmptyListOrNull' and 'toNotEmptyListOrThrow'.
@LVMVRQUXL LVMVRQUXL changed the title New builders suffixed by OrNull and OrThrow for NotEmptyList New type converters suffixed by OrNull and OrThrow for NotEmptyList Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Item related to all platforms. feature New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant