Skip to content

Binding and constraining #4

@spitz-dan-l

Description

@spitz-dan-l

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions