diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2025-04-02 18:09:46 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2025-04-02 18:09:46 +0200 |
| commit | eab38629013e34b4490be4d665142a1357c97156 (patch) | |
| tree | 57fab149aa16d438032cae5fa7a89c0b201b92ae /refined/condition.go | |
| parent | 23862346411fb921e1a45f25011c3db601f8591d (diff) | |
| download | go-gg-refinement-types-2.tar.gz | |
demonstration of refinement types without self-referential typesrefinement-types-2
The big "yuck" about this can be seen in the LiteralValue invocations in
the test code. Calling NewValue or LiteralValue is extremely convoluted
and would likely need to be wrapped through additional boilerplate at
the concrete type declaration site.
Diffstat (limited to 'refined/condition.go')
| -rw-r--r-- | refined/condition.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/refined/condition.go b/refined/condition.go new file mode 100644 index 0000000..5b43554 --- /dev/null +++ b/refined/condition.go @@ -0,0 +1,20 @@ +/******************************************************************************* +* Copyright 2025 Stefan Majewsky <majewsky@gmx.net> +* SPDX-License-Identifier: Apache-2.0 +* Refer to the file "LICENSE" for details. +*******************************************************************************/ + +package refined + +import ( + "fmt" + "regexp" +) + +// Building block for writing MatchesValue() implementations. +func RegexpMatch(rx *regexp.Regexp, value string) error { + if !rx.MatchString(value) { + return fmt.Errorf("provided value %q does not match expected pattern %q", value, rx.String()) + } + return nil +} |
