-
-
Notifications
You must be signed in to change notification settings - Fork 502
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
NonEmptyArray and ReadonlyNonEmptyArray are missing functions from Array and ReadonlyArray #1420
Comments
Thanks @jleider this kind of analysis is gold!
Note that you don't need any conversion, a As a general design decision I think that
Point 1. means that, for example,
|
Thinking twice export const matchLeft = <A, B>(f: (head: A, tail: Array<A>) => B) => (as: NonEmptyArray<A>): B => f(head(as), tail(as))
export const matchRight = <A, B>(f: (init: Array<A>, last: A) => B) => (as: NonEmptyArray<A>): B =>
f(init(as), last(as)) |
What I have added to my own extensions is a export function modifyLeft<A>(f: (a: A) => A): (nea: NonEmptyArray<A>) => NonEmptyArray<A> {
return matchLeft((head, tail) => pipe(tail, prepend(f(head))))
}
export function modifyRight<A>(f: (a: A) => A): (nea: NonEmptyArray<A>) => NonEmptyArray<A> {
return matchRight((init, last) => pipe(init, append(f(last))))
} Adding |
@mlegenhausen 👍 I would name them After scanning the 2.10.0-rc.4
2.11
|
If we distinguish more and more between |
@mlegenhausen I would keep |
This is great to know. Maybe you could add that bit of info to the top of the |
I'll open a PR to add |
🐛 Bug report
There are a number of functions that exist within
Array
andReadonlyArray
that are absent fromNonEmptyArray
andReadonlyNonEmptyArray
.Some of them may not be applicable to their
NonEmpty
variants or may return anOption<NonEmptyArray>
or a normalArray
from aNonEmptyArray
such as withfilter
style functions.At this point its a design decision and I'm not sure if its better to have these
filter
style functions acting directly upon aNonEmptyArray
which potentially return anOption<NonEmptyArray>
, implicitly convert to anArray
, or if its clearer to explicitly convert aNonEmptyArray
to a normalArray
before runningfilter
style functions. Ideally converting from aNonEmptyArray
toArray
would incur little to no runtime cost.That said, a quick glance shows these are the missing functions/instances:
Array
while others only exist withinNonEmptyArray
foldMap
andfoldMapWithIndex
listed here instead of underFoldable
andFoldableWithIndex
find*
,fold*
andmatch*
missing fromNonEmptyArray
NonEmptyArray
Also of note, the order of the documentation is different for
Array
vsNonEmptyArray
which also further complicates comparison between the two different Array types.Your environment
The text was updated successfully, but these errors were encountered: