Great little project! I found this through your post to the python-ideas list.
This issue is about the ability to both constrain a matched value and bind it at the same time.
For instance, say I want to destructure a list in head/tail style. I want to bind the first element to the head attribute of my Binding, and the rest of the list to the tail attribute. Currently there doesn't seem to be a way to do the tail part.
from destructure import Binding, match
o = Binding()
schema = [o.head, ...]
data = [1, 2, 3, 4]
guard = lambda: len(data) > 0
match(schema, data, guard) # this will match what I want, but won't bind o.tail
Very similar scenario for other constraints. You can constrain a value with e.g. ellipses, a type, a substructure, but you can't also bind that value.
Seems like there ought to be an extension that enables this.
Great little project! I found this through your post to the python-ideas list.
This issue is about the ability to both constrain a matched value and bind it at the same time.
For instance, say I want to destructure a list in head/tail style. I want to bind the first element to the
headattribute of my Binding, and the rest of the list to thetailattribute. Currently there doesn't seem to be a way to do thetailpart.Very similar scenario for other constraints. You can constrain a value with e.g. ellipses, a type, a substructure, but you can't also bind that value.
Seems like there ought to be an extension that enables this.