Closed davidchambers closed 7 years ago
I'll explain how I arrived at this pull request.
I wrote something like this, forgetting to specify the types:
const f = def('f', {}, [], _f);
I ran the code and got an unhelpful error message:
RangeError: Invalid array length
I set out to add a length check and a custom error message for an empty type array.
I remembered that we have an elegant way to avoid ad hoc type checking. :D
I defined NonEmptyArray for internal use to improve the error message.
NonEmptyArray
I decided to export NonEmptyArray (and NonEmptyString, for symmetry).
NonEmptyString
I think you can define one NonEmpty(Type) for any Type which is Eq and Monoid eq(a, empty(a.constructor))
NonEmpty(Type)
Eq
Monoid
eq(a, empty(a.constructor))
Wonderful suggestion, Irakli! Please have a look at the updated patch. :)
I'll explain how I arrived at this pull request.
I wrote something like this, forgetting to specify the types:
I ran the code and got an unhelpful error message:
I set out to add a length check and a custom error message for an empty type array.
I remembered that we have an elegant way to avoid ad hoc type checking. :D
I defined
NonEmptyArray
for internal use to improve the error message.I decided to export
NonEmptyArray
(andNonEmptyString
, for symmetry).