Skip to content

Commit

Permalink
meta2
Browse files Browse the repository at this point in the history
  • Loading branch information
rushsteve1 committed Nov 4, 2024
1 parent 31ce0ae commit c07db1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions transducers/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
// Meta-transducers are functions that take or return a transducer.
// They often can be implemented as standard transducers but are simpler this way

// Visit takes a transducer and returns a new transducer that counteracts
// that transformation and returns the original sequence unaltered.
// Visitor takes a transducer and returns a new transducer that
// counteracts the first and returns the original sequence unaltered.
// Useful for transducers with side-effcts like [Write].
// This is a higher-kinded version of [Each].
//
// This took me a very long time to figure out
func Visit[T, U any](tx Transducer[T, U]) Transducer[T, T] {
func Visitor[T, U any](tx Transducer[T, U]) Transducer[T, T] {
// Create tne new transducer that takes the sequence
return func(seq Seq[T]) Seq[T] {
// Return a new sequence
Expand Down
2 changes: 1 addition & 1 deletion transducers/transducers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestWriter(t *testing.T) {
Curry2(Map, func(i int) []byte {
return []byte(strconv.Itoa(i))
}),
Visit(Curry2(Write, io.Writer(&buf))),
Visitor(Curry2(Write, io.Writer(&buf))),
Curry2(Map, func(b []byte) string {
return string(b)
}),
Expand Down

0 comments on commit c07db1b

Please sign in to comment.