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

match if equal? #41

Open
zlee-personal opened this issue Oct 22, 2019 · 1 comment
Open

match if equal? #41

zlee-personal opened this issue Oct 22, 2019 · 1 comment

Comments

@zlee-personal
Copy link

Is there a way to match a pattern like [_, 0, _] only if the two _s are equal, and if they aren't continue to the next pattern?

@hucker
Copy link

hucker commented Mar 20, 2020

Not nicely as far as I can tell.

the best I could come up with is:

def check_seq(seq):
    return len(seq)==3 and seq[1] == 0 and seq[0]==seq[2]

def match_seq(seq):
    return 2* seq[0]

and then have the pattern just be check_seq...then you end up with:
check_seq, lambda a: match_seq(a)

This isn't great because you loose the patterns but it is compact.

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

No branches or pull requests

2 participants