go-functional icon indicating copy to clipboard operation
go-functional copied to clipboard

[Feature 🔨]: String representations for all iterators

Open BooleanCat opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe.

Printing as a string today (0.17.0) looks ugly:

counter := iter.Count()
fmt.Println(counter)
fmt.Printf("%s\n", counter)
// &{{%!s(*iter.CountIter=&{{0xc0000a6000} 0})} %!s(int=0)}

This makes it hard to debug issues when you need to print iterators.

Describe the solution you'd like

Implement the stringer interface for each iterator. The text should make it clear that it's an iterator and the kind of iterator that it is. Perhaps something like:

fmt.Printf("%s\n", iter.Count())  // Iterator<Count>
fmt.Printf("%s\n", iter.Count().Take(4)) // Iterator<Take>

I'm open to better ideas about how it should be represented.

Provide code snippets to show how this new feature might be used.

The fmt.Stringer() interface should be implemented for each iterator.

Does this incur a breaking change?

No.

Do you intend to build this feature yourself?

Maybe.

Additional context

Doesn't all need to be in one PR, I'd accept a PR for 1+ iterators. This issue is closed when all are implemented.

BooleanCat avatar Aug 30 '23 08:08 BooleanCat