Skip to content

Instantly share code, notes, and snippets.

@mschauer
Created August 7, 2017 18:18
Show Gist options
  • Select an option

  • Save mschauer/c6285e4f509e48a0e13946ca113230fa to your computer and use it in GitHub Desktop.

Select an option

Save mschauer/c6285e4f509e48a0e13946ca113230fa to your computer and use it in GitHub Desktop.
Forget the shape
using Base.Iterators
import Base: done, next, start, length, eltype, iteratorsize, HasShape, HasLength
struct UnshapedIterator{I}
it::I
UnshapedIterator{I}(it::I, a::HasShape) = new{I}(it)
UnshapedIterator{I}(it::I, a::HasLength) = new{I}(it)
end
unshaped(it::I) where {I} = UnshapedIterator{I}(it, iteratorsize(it))
done(it::UnshapedIterator, s) = done(it.it, s)
next(it::UnshapedIterator, s) = next(it.it, s)
start(it::UnshapedIterator) = start(it.it)
length(it::UnshapedIterator) = length(it.it)
eltype(it::Type{UnshapedIterator}) = eltype(it.it)
iteratorsize(::Type{<:UnshapedIterator}) = HasLength()
unshaped(zip(1:3,1:4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment