Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor internal/gpx and internal/xlsx using generics #18

Closed
dolmen opened this issue Jun 30, 2024 · 3 comments
Closed

Refactor internal/gpx and internal/xlsx using generics #18

dolmen opened this issue Jun 30, 2024 · 3 comments

Comments

@dolmen
Copy link
Contributor

dolmen commented Jun 30, 2024

Packages internal/gpx and internal/xlsx contain duplicated code that could be unfied using generics.

@dolmen
Copy link
Contributor Author

dolmen commented Jul 1, 2024

I just did an experiment using this util function that enables to use range-over-func (requires to compile with GOEXPERIMENT=rangefunc on Go 1.22):

func iterTokens[Token any, Tokenizer interface{ Token() (Token, error) }](tok Tokenizer) iter.Seq2[Token, error] {
	return func(yield func(Token, error) bool) {
		for {
			token, err := tok.Token()
			if err == io.EOF {
				break
			}
			if !yield(token, err) {
				break
			}
		}
	}
}

Result of the experiment: I don't think its worth it for now (especially because of GOEXPERIMENT).

@dolmen
Copy link
Contributor Author

dolmen commented Jul 1, 2024

See also golang/go#68259 which I just filled and which proposes to add a Tokens() iter.Seq2[Token, error] on encoding/xml.Decoder.

@dolmen
Copy link
Contributor Author

dolmen commented Jul 2, 2024

I expect this will rejected according to @muktihari's comment on another PR:
#17 (comment)

So, closing.

@dolmen dolmen closed this as completed Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant