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

["Request"] min and max methods for NonEmptyList #2593

Closed
dorians opened this issue Dec 14, 2021 · 3 comments
Closed

["Request"] min and max methods for NonEmptyList #2593

dorians opened this issue Dec 14, 2021 · 3 comments

Comments

@dorians
Copy link
Contributor

dorians commented Dec 14, 2021

What version are you currently using?

1.0.1

What would you like to see?

Kotlin's Iterable has methods minOrNull and maxOrNull:

listOf(1, 2, 3, 4, 5).minOrNull() // 1
listOf(1, 2, 3, 4, 5).maxOrNull() // 5

As a input list can be empty, they return nullable type:

emptyList<Int>().minOrNull() // null

I would be useful to have similar methods for NonEmptyList that return non-nullable values:

fun <T> NonEmptyList<T>.min(): T
fun <T> NonEmptyList<T>.max(): T

Other related methods:

  • minByOrNull
  • maxByOrNull
@nomisRev
Copy link
Member

Hey @dorians,

That'd be great! I think that method should be restricted to Comparable<T>, no?

fun <T : Comparable<T>> NonEmptyList<T>.min(): T
fun <T : Comparable<T>> NonEmptyList<T>.max(): T

If you're interested we'd love the contribution!

@dorians
Copy link
Contributor Author

dorians commented Dec 28, 2021

@nomisRev yes, you're correct! I'll create PR for this one

@serras
Copy link
Member

serras commented Jul 7, 2022

Closed by #2622

@serras serras closed this as completed Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants