Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

How to check if a list contains an element? #49

Closed
p-e-w opened this issue Dec 9, 2018 · 2 comments
Closed

How to check if a list contains an element? #49

p-e-w opened this issue Dec 9, 2018 · 2 comments

Comments

@p-e-w
Copy link
Contributor

p-e-w commented Dec 9, 2018

The best I could come up with without using imperative constructs is

contains (list, element) =
  count [for (e in list) if (e == element) e] > 0;

which is ugly and horribly inefficient. I guess the efficiency problem could be solved using a while loop, but the code would be even uglier.

Might it make sense to add a built-in contains operator?

doug-moen added a commit that referenced this issue Dec 10, 2018
@doug-moen
Copy link
Member

Thanks for the suggestion. It is now implemented.

@p-e-w
Copy link
Contributor Author

p-e-w commented Dec 10, 2018

Thanks for the quick followup 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants