I'm sure there's a use-case for this, but I'm not coming up with one off the top of my head. This comes across as an extremely rare type of problem to encounter.
What's the purpose of only binding x and z if the first argument of Bar matches? What if it doesn't match? Is an exception thrown? Are x,z just None?
[Note: I'm talking about the example, not the @case decorator, which does seem useful]
Edit:
After reading the library examples, the explanation above is not entirely clear:
with patterns:
Foo(x, Bar(3, z)) << Foo(4, Bar(3, 8))
here's the rest of the example:
print x # 4
print z # 8
I was thinking that somehow a new Foo instance was created only when the pattern matched. (Oh, and an exception is thrown when the match fails)
What's the purpose of only binding x and z if the first argument of Bar matches? What if it doesn't match? Is an exception thrown? Are x,z just None?
[Note: I'm talking about the example, not the @case decorator, which does seem useful]
Edit:
After reading the library examples, the explanation above is not entirely clear:
here's the rest of the example: I was thinking that somehow a new Foo instance was created only when the pattern matched. (Oh, and an exception is thrown when the match fails)