History

Rename Transform() back to Map()

- better discoverability - better pairing with .Filter() - shorter Fixes #45

Gregory Petrosyan committed 3 years ago

Commit cce37f21 parent 6dec3de3 files · +5 −5Browse files

Unified · Split

3 files
  1. combinators.go +2 −2
  2. combinators_external_test.go +1 −1
  3. combinators_test.go +2 −2
combinators.go+2−2
@@ -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
116func Transform[U any, V any](g *Generator[U], fn func(U) V) *Generator[V] {116func 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
128func (g *mappedGen[U, V]) String() string {128func (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
132func (g *mappedGen[U, V]) value(t *T) V {132func (g *mappedGen[U, V]) value(t *T) V {
combinators_external_test.go+1−1
@@ -76,7 +76,7 @@ func TestFilter(t *testing.T) { · 75 unmodified lines
76func TestMap(t *testing.T) {76func 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")
combinators_test.go+2−2
@@ -16,8 +16,8 @@ type intPair struct { · 15 unmodified lines
16func BenchmarkHeavyChain3(b *testing.B) {16func 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++ {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t