Skip to content

Commit

Permalink
Rename Transform() back to Map()
Browse files Browse the repository at this point in the history
- better discoverability
- better pairing with .Filter()
- shorter

Fixes #45
  • Loading branch information
flyingmutant committed Jan 8, 2023
1 parent 6dec3de commit cce37f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions combinators.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func find[V any](gen func(*T) (V, bool), t *T, tries int) V {
panic(invalidData(fmt.Sprintf("failed to find suitable value in %d tries", tries)))
}

func Transform[U any, V any](g *Generator[U], fn func(U) V) *Generator[V] {
func Map[U any, V any](g *Generator[U], fn func(U) V) *Generator[V] {
return newGenerator[V](&mappedGen[U, V]{
g: g,
fn: fn,
Expand All @@ -126,7 +126,7 @@ type mappedGen[U any, V any] struct {
}

func (g *mappedGen[U, V]) String() string {
return fmt.Sprintf("Transform(%v, %T)", g.g, g.fn)
return fmt.Sprintf("Map(%v, %T)", g.g, g.fn)
}

func (g *mappedGen[U, V]) value(t *T) V {
Expand Down
2 changes: 1 addition & 1 deletion combinators_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestFilter(t *testing.T) {
func TestMap(t *testing.T) {
t.Parallel()

g := Transform(Int(), strconv.Itoa)
g := Map(Int(), strconv.Itoa)

Check(t, func(t *T) {
s := g.Draw(t, "s")
Expand Down
4 changes: 2 additions & 2 deletions combinators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type intPair struct {
func BenchmarkHeavyChain3(b *testing.B) {
t := newT(nil, newRandomBitStream(baseSeed(), false), false, nil)
g1 := Custom(func(t *T) int { return Int().Draw(t, "") })
g2 := Transform(g1, func(i int) intPair { return intPair{i, i << 13} })
g3 := Transform(g2, func(p intPair) int { return p.x + p.y })
g2 := Map(g1, func(i int) intPair { return intPair{i, i << 13} })
g3 := Map(g2, func(p intPair) int { return p.x + p.y })
b.ResetTimer()

for i := 0; i < b.N; i++ {
Expand Down

0 comments on commit cce37f2

Please sign in to comment.