Skip to content

Rethink Capture() design #685

@ilyash-b

Description

@ilyash-b

Non-matching Capture() results default values by design.

In some situations such as AtPath(Any, Capture(...)) these default values are not ergonomic.

$ ngs -p '["a", 1] =~ AtPath(Any, Capture(Int))'
<MatchSuccess matches=[null,null,1] pattern=<AtPath path_pattern=<Type Any with 0 constructor(s) and 1 meta entries> value_pattern=<Capture pattern=<Type Int with 8 constructor(s) and 1 meta entries> name=null dflt=null>> named={}>

Thought: introduce filterr() for recursive filter, solving the exact use case above. Then think about which other methods need the r counterpart. eachrr(). How not to confuse with r suffix in other languages which typically means search from right and recursive. Maybe use _rec suffix.

Thought: non-matching alternative/branch should leave no traces in positional or named matches (captures).

Open issue about filterr(), eachr() and all potential data structures walkers - pre or post visit - how to specify?

_rec suffix sounds like reasonable price to pay for recursive walk

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions