Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Commit

Permalink
Julia 0.4 compat for iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcjones committed May 6, 2015
1 parent e1c0743 commit f8a76b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.3
# Compat
Compat
12 changes: 5 additions & 7 deletions src/Iterators.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Iterators
using Base
# Not needed now since it does not work
# using Compat

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

export
Expand Down Expand Up @@ -612,16 +610,16 @@ length(it::Binomial) = binomial(it.n,it.k)

subsets(xs,k) = Binomial(xs,length(xs),k)

start(it::Binomial) = (Int64[1:it.k],false)
start(it::Binomial) = (collect(Int64, 1:it.k), false)

function next(it::Binomial,state::(Array{Int64,1},Bool))
function next(it::Binomial, state::(@compat Tuple{Array{Int64,1}, Bool}))
idx = state[1]
set = it.xs[idx]
i = it.k
while(i>0)
if idx[i] < it.n - it.k + i
idx[i] += 1
idx[i+1:it.k] = [idx[i]+1:idx[i]+it.k-i]
idx[i+1:it.k] = idx[i]+1:idx[i]+it.k-i
break
else
i -= 1
Expand All @@ -634,7 +632,7 @@ function next(it::Binomial,state::(Array{Int64,1},Bool))
end
end

done(it::Binomial,state::(Array{Int64,1},Bool)) = state[2]
done(it::Binomial, state::(@compat Tuple{Array{Int64,1}, Bool})) = state[2]


# Unfolding (anamorphism)
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ test_groupby(
@test collect(subsets([:a, :b, :c],1)) == Any[Symbol[:a], Symbol[:b], Symbol[:c]]
@test collect(subsets([:a, :b, :c],2)) == Any[Symbol[:a,:b], Symbol[:a,:c], Symbol[:b,:c]]
@test collect(subsets([:a, :b, :c],3)) == Any[Symbol[:a,:b,:c]]
@test length(collect(subsets([1:4],1))) == binomial(4,1)
@test length(collect(subsets([1:4],2))) == binomial(4,2)
@test length(collect(subsets([1:4],3))) == binomial(4,3)
@test length(collect(subsets([1:4],4))) == binomial(4,4)
@test length(collect(subsets(collect(1:4),1))) == binomial(4,1)
@test length(collect(subsets(collect(1:4),2))) == binomial(4,2)
@test length(collect(subsets(collect(1:4),3))) == binomial(4,3)
@test length(collect(subsets(collect(1:4),4))) == binomial(4,4)


## @itr
Expand Down

0 comments on commit f8a76b0

Please sign in to comment.