Capture type

A pattern that captures the matching value.

Methods

=~(x:Any, c:Capture, mc:MatchContext)internal Source: stdlib.ngs:1148
Undocumented
init(c:Capture, pattern:Any=method) Source: stdlib.ngs:1131
Make a pattern that captures the matching value. The matched value will be stored in MatchContext.positional

Parameters

patternOptional pattern to match. Defaults to Any.

Example

m = [1,2] =~ Capture([Capture(Int), Capture(Int)])  # m.matches =~ [Arr, 1, 2]
init(c:Capture, name:Str, pattern:Any=method) Source: stdlib.ngs:1142
Make a pattern that captures the matching value. The matched value will be stored in MatchContext.named[name]

Parameters

patternOptional pattern to match. Defaults to Any.

Example

m = {"a": 1, "b": 2} =~ {"a": Capture("arg1"), "b": Capture("arg2")}; m.named.arg1 + m.named.arg2  # 3
m = {"a": 1, "b": 2} =~ {"a": Capture("arg1", Int), "b": Capture("arg2", Str)}  # Doesn't match - b is Int