Skip to content
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

remove Iterators.jl #49

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ Combinatorics.jl is licensed under the MIT License:
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The chain function is from Iterators.jl and is licensed under the MIT License:

>Copyright (c) 2012-2016: Daniel Jones, Stefan Karpinski, Simon Kornblith, Kevin Squire, Jeff Bezanson, Tim Holy, Jonathan Malmaud, Eric Davies, and other contributors.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
julia 0.5
Compat 0.18.0
Polynomials
Iterators
4 changes: 2 additions & 2 deletions src/Combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ __precompile__(true)

module Combinatorics

using Compat, Polynomials, Iterators
using Compat, Polynomials

import Base: start, next, done, length, eltype

Expand All @@ -20,5 +20,5 @@ include("combinations.jl")
include("permutations.jl")
include("partitions.jl")
include("youngdiagrams.jl")

include("iterators.jl")
end #module
59 changes: 59 additions & 0 deletions src/iterators.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# From Iterators.jl. Moved here since Iterators.jl is not precompile safe anymore.

# Concatenate the output of n iterators
immutable Chain{T<:Tuple}
xss::T
end

# iteratorsize method defined at bottom because of how @generated functions work in 0.6 now

"""
chain(xs...)

Iterate through any number of iterators in sequence.
```jldoctest
julia> for i in chain(1:3, ['a', 'b', 'c'])
@show i
end
i = 1
i = 2
i = 3
i = 'a'
i = 'b'
i = 'c'
```
"""
chain(xss...) = Chain(xss)

Base.length(it::Chain{Tuple{}}) = 0
Base.length(it::Chain) = sum(length, it.xss)

Base.eltype{T}(::Type{Chain{T}}) = typejoin([eltype(t) for t in T.parameters]...)

function Base.start(it::Chain)
i = 1
xs_state = nothing
while i <= length(it.xss)
xs_state = start(it.xss[i])
if !done(it.xss[i], xs_state)
break
end
i += 1
end
return i, xs_state
end

function Base.next(it::Chain, state)
i, xs_state = state
v, xs_state = next(it.xss[i], xs_state)
while done(it.xss[i], xs_state)
i += 1
if i > length(it.xss)
break
end
xs_state = start(it.xss[i])
end
return v, (i, xs_state)
end

Base.done(it::Chain, state) = state[1] > length(it.xss)