Background: I'm currently working on making the
Gomega matcher library iterator-aware as first-class citizens. That is, matchers working on "collection" types such as slice and map will then accept iterator functions and act accordingly. As I also work on updating the matcher documentation I'm struggling with terminology/wording. Please keep in mind that the matcher documentation needs to be sweet and short, as there are repetitive mentioning of iterator handling appearing in multiple places.
To use a concrete example,
BeEmpty() currently pre-iterator is described as follows:
[...] succeeds if ACTUAL is, in fact, empty. ACTUAL must be of type string, array, map, chan, or slice. It is an error for it to have any other type.
Here, I want now to add that ACTUAL additionally can be an iterator in a hopefully concise, yet compact way. Please note that we don't want to support any range-able value here, just iterators.
Now, does the term "
iterator" always refer to a function, and in particular, to "
a function that passes successive elements of a sequence to a callback function"? [
package iter, section Iterators]
How can I guide devs new to Go's iterator pattern to quickly grasp that ACTUAL can be a function that is "assignable to" (i.e., "AssignableTo" in reflect speak) iter.Seq and/or iter.Seq2 . Is the following phrasing (bold to emphasize the new part) acceptable? Can this be improved (without singing an opera)?
[...] succeeds if ACTUAL is, in fact, empty. ACTUAL must be of type string, array, map, chan, or slice. Starting with Go 1.23, ACTUAL can be also an iterator function with an iter.Seq or iter.Seq2-like signature . It is an error for it to have any other type.