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

NonEmptyList #177

Open
brendanmaguire opened this issue Nov 10, 2023 · 0 comments · May be fixed by #178
Open

NonEmptyList #177

brendanmaguire opened this issue Nov 10, 2023 · 0 comments · May be fixed by #178

Comments

@brendanmaguire
Copy link
Contributor

brendanmaguire commented Nov 10, 2023

Is your feature request related to a problem? Please describe.
I have found NonEmptyList from the Scala Cats library very useful in the past. I'd like to implement a similar collection type in Expression. Is this something you would be open to @dbrattli ?

Describe the solution you'd like
Just a few examples outlined below. Overall I'd see it working in a similar way to expression.collections.Block (i.e. an immutable collection).

list(NonEmptyList.one(1)) == [1]

list(NonEmptyList.of(1, 2, 3)) == [1, 2, 3]

NonEmptyList.from([1, 2, 3]).map(list) == Some([1, 2, 3])

NonEmptyList.from([]) == Nothing

def do_something_with_list_that_must_be_non_empty(l: NonEmptyList):
    # do things with elements in `l`

Describe alternatives you've considered
Doing this everywhere in your code:

def do_something_with_list_that_must_be_non_empty(l: list):
    if l:
        # do things with elements in `l`
brendanmaguire added a commit to brendanmaguire/Expression that referenced this issue Nov 11, 2023
* This collection guarentees to have at least one element
* Uses Scala cats [NonEmptyList](https://typelevel.org/cats/datatypes/nel.html) as inspiration

Closes dbrattli#177
@brendanmaguire brendanmaguire linked a pull request Nov 11, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant