You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes I want to use an Array util that requires a NonEmptyArray like Array.group, but the context allows for an empty array. This is obviously solved by Array.match
The problem is that this produces a less than ideal type, for the above it'll be never[] | [[Foo, ...Foo[], ....[Foo, ... Foo[]]].
It is not inferable nor can I manually type Array.empty to match since [Foo,...Foo[]][] is not the same as the non-empty tuple type (so you get [Foo,...Foo[]][] | [[Foo, ...Foo[], ....[Foo, ... Foo[]]]).
What is the feature you are proposing to solve the problem?
Since Array.mapNonEmpty has been integrated into Array.map and killed off, I propose to exume its body and reanimating it to do our biddings. That is, allow to map over a non-empty case of an array, removing non-emptiness on the inferred result
This will also solve some recurring issues raised by users who express a desire to work on 0..n sized arrays using 1..n dependant utils, common in cases where validation or input arrives outside of effect , where types are less precise, and the strictness of checking for non-emptiness might feel redundant
Other name suggestions: .applyNonEmpty, .forNonEmpty, .onNonEmpty, or .extendNonEmpty
Though none are stellar lol
What is the problem this feature would solve?
Sometimes I want to use an
Array
util that requires aNonEmptyArray
likeArray.group
, but the context allows for an empty array. This is obviously solved byArray.match
(Yeah yeah tacit usage)
The problem is that this produces a less than ideal type, for the above it'll be
never[] | [[Foo, ...Foo[], ....[Foo, ... Foo[]]]
.It is not inferable nor can I manually type
Array.empty
to match since[Foo,...Foo[]][]
is not the same as the non-empty tuple type (so you get[Foo,...Foo[]][] | [[Foo, ...Foo[], ....[Foo, ... Foo[]]]
).What is the feature you are proposing to solve the problem?
Since
Array.mapNonEmpty
has been integrated intoArray.map
and killed off, I propose to exume its body and reanimating it to do our biddings. That is, allow to map over a non-empty case of an array, removing non-emptiness on the inferred resultThis will also solve some recurring issues raised by users who express a desire to work on
0..n
sized arrays using1..n
dependant utils, common in cases where validation or input arrives outside of effect , where types are less precise, and the strictness of checking for non-emptiness might feel redundantOther name suggestions:
.applyNonEmpty
,.forNonEmpty
,.onNonEmpty
, or.extendNonEmpty
Though none are stellar lol
What alternatives have you considered?
The text was updated successfully, but these errors were encountered: