Map::Match

Provide a Map where keys are regular expressions

NAME

Map::Match - Provide a Map where keys are regular expressions

SYNOPSIS

use Map::Match;

my %m is Map::Match = foo => 42, b16ar => 666, baz18 => 137;

.say for %m<a>;  # 666ā¤137ā¤, same as / a /

.say for %m{ / \d >> / };    # 137ā¤

.say for %m{ / \d >> / }:k;  # baz18ā¤

DESCRIPTION

Map::Match provides an implementation of the Map interface where key values are interpreted as regular expressions. This has the following implications with regards to the normal behaviour of Maps:

CAN RETURN MORE THAN ONE

Since a regular expression can match multiple times, you can receive more than one value back from a single key. Therefore, a Slip will always be returned as the value.

ALWAYS A SLIP

The value returned from any Map access is always a Slip, albeit potentially empty. This is different from a normal Map where Nil would be returned when specifying a key that does not exist in the Map.

NON-REGEX KEY ASSUMED TO BE REGEX

If you specify a Str as a key, or something that can be coerced to a Str, it will be interpreted as being interpolated in a Regex.

AUTHOR

Elizabeth Mattijsen [email protected]

Source can be located at: https://github.com/lizmat/Map-Match . Comments and Pull Requests are welcome.

COPYRIGHT AND LICENSE

Copyright 2021 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

Map::Match v0.0.1

Provide a Map where keys are regular expressions

Authors

  • Elizabeth Mattijsen

License

Artistic-2.0

Dependencies

Map::Agnostic:ver<0.0.6>:auth<zef:lizmat>

Test Dependencies

Provides

  • Map::Match

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.