diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-10-18 19:33:33 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-10-18 19:33:33 +0200 |
| commit | 29b3b63b404c6a2cec28ff5eb067efe0b054a37f (patch) | |
| tree | 8086cc0a5bcf0bffb1458c19d7fae45f3b50a1df /options | |
| parent | 793e1705b4c34405f24d0f95ab532b68e8db673a (diff) | |
| download | go-gg-29b3b63b404c6a2cec28ff5eb067efe0b054a37f.tar.gz | |
add option.Option.Map()
Diffstat (limited to 'options')
| -rw-r--r-- | options/options.go | 7 | ||||
| -rw-r--r-- | options/options_test.go | 6 |
2 files changed, 2 insertions, 11 deletions
diff --git a/options/options.go b/options/options.go index 429f31a..c96cdf9 100644 --- a/options/options.go +++ b/options/options.go @@ -32,11 +32,8 @@ func IsNoneOrZero[T comparable](o Option[T]) bool { // Map applies the given function to the value contained in o, if there is one. func Map[T, U any](o Option[T], mapping func(T) U) Option[U] { - if t, ok := o.Unpack(); ok { - return Some(mapping(t)) - } else { - return None[U]() - } + // TODO: deprecate + return o.Map(mapping) } // Max returns the largest of its input values, while disregarding None values. diff --git a/options/options_test.go b/options/options_test.go index 89b9e14..acb11e4 100644 --- a/options/options_test.go +++ b/options/options_test.go @@ -4,7 +4,6 @@ package options import ( - "strconv" "testing" "go.xyrillian.de/gg/assert" @@ -22,11 +21,6 @@ func TestIsNoneOrZero(t *testing.T) { assert.Equal(t, IsNoneOrZero(Some(1)), false) } -func TestMap(t *testing.T) { - assert.Equal(t, Map(None[int](), strconv.Itoa), None[string]()) - assert.Equal(t, Map(Some(42), strconv.Itoa), Some("42")) -} - func TestMax(t *testing.T) { assert.Equal(t, Max[int](), None[int]()) assert.Equal(t, Max(None[int]()), None[int]()) |
