-
-
Notifications
You must be signed in to change notification settings - Fork 443
Description
Is there an existing issue for this?
- I have searched the existing issues
What problem does this feature solve?
Currently Formatter.Format
accepts an Iterator
argument, but it's hard (or at any rate less performant) to adapt a standard library iterator (e.g. iter.Seq[chroma.Token]
) into this form.
Specifically, we can do it with something like this code but iter.Pull
is considerably slower than a straight function invocation so this is less than ideal. Alternatively we could use slices.Collect
to collect the tokens into a slice and then define a simple chroma.Iterator
to iterate over those items, but that ends up allocating the entire slice twice, because the first thing that Format
does is collect all the tokens into a slice!
What feature do you propose?
The easiest thing here might be to provide an entry point that takes a slice rather than an iterator: essentially just export Formatter.writeHTML
as is.
Alternatively, perhaps define
type IteratorV2 iter.Seq[Token]
and define new entry points in terms of that (it's straightforward to adapt the old entry points to use that interface).
Alternatively (most invasive) define an entirely new API in terms of the new stdlib iterator standard.