Pfx type

Prefix subsequence of a sequence

Direct parent types

SubSeq
Undocumented
Direct subtypes: 3

Direct children types

MaybePfx
Prefix that might or might not be present for (-) to succeed
MustPfx
Prefix that must be present for ~ matching to succeed

Constructors

Pfx(val:Any) Source: stdlib.ngs:6894
Convenience method for creating MustPfx

Returns

MustPfx

Methods

-(s:Str, pfx:Pfx) Source: stdlib.ngs:6914
Return string without the prefix. Throws InvalidArgument if pfx is MustPfx but s does not start with it.

Parameters

soriginal string
pfxprefix to get rid of

Returns

s without pfx

Example

"abcde" - Pfx("ab")  # "cde"
"abcde" - Pfx("xy")  # InvalidArgument exception
"abcde" - MaybePfx("xy")  # "abcde"
=~(x:Eachable1, pfx:Pfx, mc:MatchContext) Source: stdlib.ngs:6989
Undocumented

Example

[1,2,3] =~ Pfx([1,2])
~(s:Str, pfx:Pfx) Source: stdlib.ngs:6964
Check whether s starts with pfx.

Returns

MatchResult

Example

"abcde" ~ Pfx("ab")  # <MatchSuccess matches=[ab] pattern=<MustPfx ab> before= after=cde>
"abcde" ~ Pfx("xy")  # <MatchFailure >