- better discoverability - better pairing with .Filter() - shorter Fixes #45
Unified · Split
| @@ -113,7 +113,7 @@ func find[V any](gen func(*T) (V, bool), t *T, tries int) V { · 112 unmodified lines | |||
| 113 | panic(invalidData(fmt.Sprintf("failed to find suitable value in %d tries", tries))) | 113 | panic(invalidData(fmt.Sprintf("failed to find suitable value in %d tries", tries))) |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | func Transform[U any, V any](g *Generator[U], fn func(U) V) *Generator[V] { | 116 | func Map[U any, V any](g *Generator[U], fn func(U) V) *Generator[V] { |
| 117 | return newGenerator[V](&mappedGen[U, V]{ | 117 | return newGenerator[V](&mappedGen[U, V]{ |
| 118 | g: g, | 118 | g: g, |
| 119 | fn: fn, | 119 | fn: fn, |
| @@ -126,7 +126,7 @@ type mappedGen[U any, V any] struct { · 6 unmodified lines | |||
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | func (g *mappedGen[U, V]) String() string { | 128 | func (g *mappedGen[U, V]) String() string { |
| 129 | return fmt.Sprintf("Transform(%v, %T)", g.g, g.fn) | 129 | return fmt.Sprintf("Map(%v, %T)", g.g, g.fn) |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | func (g *mappedGen[U, V]) value(t *T) V { | 132 | func (g *mappedGen[U, V]) value(t *T) V { |
| @@ -76,7 +76,7 @@ func TestFilter(t *testing.T) { · 75 unmodified lines | |||
| 76 | func TestMap(t *testing.T) { | 76 | func TestMap(t *testing.T) { |
| 77 | t.Parallel() | 77 | t.Parallel() |
| 78 | 78 | ||
| 79 | g := Transform(Int(), strconv.Itoa) | 79 | g := Map(Int(), strconv.Itoa) |
| 80 | 80 | ||
| 81 | Check(t, func(t *T) { | 81 | Check(t, func(t *T) { |
| 82 | s := g.Draw(t, "s") | 82 | s := g.Draw(t, "s") |
| @@ -16,8 +16,8 @@ type intPair struct { · 15 unmodified lines | |||
| 16 | func BenchmarkHeavyChain3(b *testing.B) { | 16 | func BenchmarkHeavyChain3(b *testing.B) { |
| 17 | t := newT(nil, newRandomBitStream(baseSeed(), false), false, nil) | 17 | t := newT(nil, newRandomBitStream(baseSeed(), false), false, nil) |
| 18 | g1 := Custom(func(t *T) int { return Int().Draw(t, "") }) | 18 | g1 := Custom(func(t *T) int { return Int().Draw(t, "") }) |
| 19 | g2 := Transform(g1, func(i int) intPair { return intPair{i, i << 13} }) | 19 | g2 := Map(g1, func(i int) intPair { return intPair{i, i << 13} }) |
| 20 | g3 := Transform(g2, func(p intPair) int { return p.x + p.y }) | 20 | g3 := Map(g2, func(p intPair) int { return p.x + p.y }) |
| 21 | b.ResetTimer() | 21 | b.ResetTimer() |
| 22 | 22 | ||
| 23 | for i := 0; i < b.N; i++ { | 23 | for i := 0; i < b.N; i++ { |