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
max and min methods for NonEmptyList #2622
Changes from 1 commit
c504b8d
69f6a04
df578fd
220a11e
4720d90
0c49a62
0fd10b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -383,6 +383,12 @@ public class NonEmptyList<out A>( | |
map(head, b.head, c.head, d.head, e.head, f.head, g.head, h.head, i.head, j.head), | ||
tail.zip(b.tail, c.tail, d.tail, e.tail, f.tail, g.tail, h.tail, i.tail, j.tail, map) | ||
) | ||
|
||
public inline fun <B : Comparable<B>> minBy(selector: (A) -> B): A = | ||
minByOrNull(selector) ?: head | ||
|
||
public inline fun <B : Comparable<B>> maxBy(selector: (A) -> B): A = | ||
maxByOrNull(selector) ?: head | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
} | ||
|
||
public fun <A> nonEmptyListOf(head: A, vararg t: A): NonEmptyList<A> = | ||
|
@@ -397,6 +403,12 @@ public operator fun <A : Comparable<A>> NonEmptyList<A>.compareTo(other: NonEmpt | |
public fun <A> NonEmptyList<NonEmptyList<A>>.flatten(): NonEmptyList<A> = | ||
this.flatMap(::identity) | ||
|
||
public inline fun <T : Comparable<T>> NonEmptyList<T>.min(): T = | ||
minOrNull() ?: head | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
||
public inline fun <T : Comparable<T>> NonEmptyList<T>.max(): T = | ||
maxOrNull() ?: head | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
||
public fun <A, B> NonEmptyList<Pair<A, B>>.unzip(): Pair<NonEmptyList<A>, NonEmptyList<B>> = | ||
this.unzip(::identity) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont need
?: head
, justminByOrNull(selector)!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!!
should indeed be safe here, I think it results in a faster binary but not 100% sure actually.