SHARE
TWEET

Untitled

a guest Nov 17th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct EveryNth{T<:Integer}
  2.     n::T
  3.     start::T
  4.     stop::T
  5. end
  6.  
  7. function Base.iterate(i::EveryNth{T}, state=(i.start, zero(T))) where T
  8.     e, c = state
  9.     c > i.stop && return nothing
  10.     e, (e+i.n, c+i.n)
  11. end
  12.  
  13. Base.length(iter::EveryNth) = Int((iter.stop - iter.start) / iter.n)
  14. Base.eltype(iter::EveryNth{T}) where T = T
  15.  
  16. iter = EveryNth(2, 0, 10)
  17.  
  18. length(iter)
  19. eltype(iter)
  20.  
  21. for i = iter
  22.     println(i)
  23. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top