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

Support for NonEmptyArray #50

Closed
haejunejung opened this issue Aug 26, 2024 · 0 comments · Fixed by #66
Closed

Support for NonEmptyArray #50

haejunejung opened this issue Aug 26, 2024 · 0 comments · Fixed by #66
Labels
enhancement New feature or request

Comments

@haejunejung
Copy link
Owner

haejunejung commented Aug 26, 2024

It provides support for NonEmptyArray.

There are some situations where you need to ensure that an array is not empty before performing operations on it. Using NonEmptyArray helps you handle cases safely.

Here is a detailed example.

const numbersArray: number[] = [];
const getFirstValue = (array: number[]) => array[0];
console.log(getFirstValue(numbersArray) // undefined, there is no type error.

const numbersArray: NonEmptyArray<number> = [] // type error. It should have one or more elements.

const nonEmptyNumbersArray: NonEmptyArray<number> = [1,2,3];
const getFirstValue = (array: NonEmptyArray<number>) => array[0]; // we can handle only the success case.

Here's a detailed. playground.

@haejunejung haejunejung added the enhancement New feature or request label Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant