Skip to content

Add List.ends_with?/2 #13768

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

Merged
merged 2 commits into from
Aug 9, 2024
Merged

Add List.ends_with?/2 #13768

merged 2 commits into from
Aug 9, 2024

Conversation

sabiwara
Copy link
Contributor

@sabiwara sabiwara commented Aug 9, 2024

We have several options here:

  1. just call :lists.suffix (if so, perhaps we can do the same for starts_with? / prefix)
  2. copy its exact implementation
  3. this PR implementation - inspired by 2. but walking two lists at once and having a consistent FunctionClauseError with starts_with?/2 (see these tests)

@whatyouhide
Copy link
Member

Why not call :lists.suffix/2 as you mentioned in 1.?

Also, this might be a silly ask, but what do you think about adding a test to stream_data for this? We have tests for Elixir stdlib in there 🙃

@josevalim
Copy link
Member

We don't need to keep compatibility between exceptions, so delegating to :lists.suffix is fine by me. :)

@sabiwara
Copy link
Contributor Author

sabiwara commented Aug 9, 2024

Sounds good, will go with :lists.suffix 👍

Also, this might be a silly ask, but what do you think about adding a test to stream_data for this? We have tests for Elixir stdlib in there 🙃

I can! If we delegate, we'd be testing erlang's stdlib I guess, but nothing's wrong with that :)

@whatyouhide
Copy link
Member

@sabiwara I mean we are wrapping it and we might change impl, so yeah I think still we are testing Elixir. Also, I suggested this because of the "complex" spec you wrote for the function: when I see something like that, I always thing about a property to write 😄

Copy link
Member

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to inline this but looks good to me 👍

@sabiwara
Copy link
Contributor Author

sabiwara commented Aug 9, 2024

Not sure if we want to inline

Good point, that would make sense I think?

@josevalim
Copy link
Member

We typically only inline when there is a native implementation on the other side. So this is good to go.

PS: Plus, if the type system works out, anything that is not a native implementation will have to be rewritten in pure Elixir so Elixir can prove it is correct in core.

@sabiwara sabiwara merged commit e770710 into elixir-lang:main Aug 9, 2024
9 checks passed
@sabiwara sabiwara deleted the list-ends-with branch August 9, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants