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 NotEmptyMap #179

Closed
21 tasks done
Tracked by #159
LVMVRQUXL opened this issue Aug 20, 2023 · 1 comment
Closed
21 tasks done
Tracked by #159
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 NotEmptyMap 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 NotEmptyMap.kt file after the toNotEmptyMap function.
Their tests should be declared in the NotEmptyMapTest class after the map_toNotEmptyMap_should_fail_with_an_empty_Map function.

Dependencies

This issue is blocked by the following ones:

Checklist

Function signatures
/**
 * Returns a [NotEmptyMap] containing all the entries of this map, or returns
 * `null` if this map is [empty][Map.isEmpty].
 *
 * Here's some usage examples:
 *
 * ```kotlin
 * var map: Map<Char, Int> = mapOf('a' to 1, 'b' to 2)
 * var result: NotEmptyMap<Char, Int>? = map.toNotEmptyMapOrNull()
 * println(result) // {a=1, b=2}
 *
 * map = emptyMap()
 * result = map.toNotEmptyMapOrNull()
 * println(result) // null
 * ```
 *
 * Please note that changes made to the original map will not be reflected on
 * the resulting [NotEmptyMap].
 *
 * ```kotlin
 * val original: MutableMap<Char, Int> = mutableMapOf('a' to 1, 'b' to 2)
 * val notEmptyMap: NotEmptyMap<Char, Int>? = original.toNotEmptyMapOrNull()
 * println(original) // {a=1, b=2}
 * println(notEmptyMap) // {a=1, b=2}
 *
 * original.clear()
 * println(original) // {}
 * println(notEmptyMap) // {a=1, b=2}
 * ```
 *
 * You can use the [toNotEmptyMapOrThrow] function for throwing an
 * [IllegalArgumentException] instead of returning `null` when this map is
 * [empty][Map.isEmpty].
 */
@ExperimentalCollectionApi
@ExperimentalSinceKotoolsTypes("4.3.1")
public fun <K, V> Map<K, V>.toNotEmptyMapOrNull(): NotEmptyMap<K, V>? {
    TODO()
}

/**
 * Returns a [NotEmptyMap] containing all the entries of this map, or throws an
 * [IllegalArgumentException] if this map is [empty][Map.isEmpty].
 *
 * Here's some usage examples:
 *
 * ```kotlin
 * var map: Map<Char, Int> = mapOf('a' to 1, 'b' to 2)
 * var result: NotEmptyMap<Char, Int> = map.toNotEmptyMapOrThrow()
 * println(result) // {a=1, b=2}
 *
 * map = emptyMap()
 * map.toNotEmptyMapOrThrow() // IllegalArgumentException
 * ```
 *
 * Please note that changes made to the original map will not be reflected on
 * the resulting [NotEmptyMap].
 *
 * ```kotlin
 * val original: MutableMap<Char, Int> = mutableMapOf('a' to 1, 'b' to 2)
 * val notEmptyMap: NotEmptyMap<Char, Int> = original.toNotEmptyMapOrThrow()
 * println(original) // {a=1, b=2}
 * println(notEmptyMap) // {a=1, b=2}
 *
 * original.clear()
 * println(original) // {}
 * println(notEmptyMap) // {a=1, b=2}
 * ```
 *
 * You can use the [toNotEmptyMapOrNull] function for returning `null` instead
 * of throwing an [IllegalArgumentException] when this map is
 * [empty][Map.isEmpty].
 */
@ExperimentalCollectionApi
@ExperimentalSinceKotoolsTypes("4.3.1")
public fun <K, V> Map<K, V>.toNotEmptyMapOrThrow(): NotEmptyMap<K, V> {
    TODO()
}
Entry in changelog
### Added

**Experimental** builders suffixed by `OrNull` and `OrThrow` for the following
types:
- `NotEmptyMap` (issue [#179] implemented by [@YourGitHubProfile](#)).

[#179]: https://github.com/kotools/types/issues/179
Commit message
feat(#179): add experimental builders for 'NotEmptyMap'

New builders: 'toNotEmptyMapOrNull' and 'toNotEmptyMapOrThrow'.
These are not implemented yet.
  • Implement the toNotEmptyMapOrThrow 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(#179): implement the 'toNotEmptyMapOrThrow' function
  • Implement the toNotEmptyMapOrNull 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(#179): implement the 'toNotEmptyMapOrNull' 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: 'toNotEmptyMapOrNull' and 'toNotEmptyMapOrThrow'.
@LVMVRQUXL
Copy link
Contributor Author

Done.

@LVMVRQUXL LVMVRQUXL changed the title New builders suffixed by OrNull and OrThrow for NotEmptyMap New type converters suffixed by OrNull and OrThrow for NotEmptyMap Oct 22, 2023
@LVMVRQUXL LVMVRQUXL changed the title New type converters suffixed by OrNull and OrThrow for NotEmptyMap New type converters suffixed by OrNull and OrThrow for NotEmptyMap 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