-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Concatenating iterator #16708
RFC: Concatenating iterator #16708
Conversation
|
||
function Concat(c) | ||
s = start(c) | ||
done(c, s) && error("argument to Concat(it) must contain at least one element") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw(ArgumentError("argument to Concat must contain at least one element"))
would be more consistent with other iterator constructor error conditions
04c2732
to
32c3cd4
Compare
|
||
import Base.concat | ||
|
||
@test collect((concat((i:i+10 for i in 1:3)))) == [1:11 2:12 3:13] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could write it like this collect(concat(i:i+10 for i in 1:3))
wouldn't you?
Thinking about this some more, I'm not sure it adds much value over |
The one thing what I found is nice about having a iterator implementing this (at the cost of peeking at the first element) is that it combines well with other iterators. Concatenation along a different dimension becomes
and concatenation two levels deep is |
Maybe it is not an atypical situation that information about length becomes known as soon as the iterator got started and not before -- and that is all what is needed in |
Is there a utility of having this as a shaped iterator as opposed to just |
An iterator that concatenates the elements of its argument, see #16622 . For example
It produces the elements in the same order as
flatten
. To determine the shape of the children it peaks at the first element of the argument. This implementation works for iterators which have theHasShape
trait. Iterators withHasLength
trait can be incorporated in a next step if the proposed design is sound.