From 61565ad09fe68330c4c2a816a665e4b748adfb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 29 Jun 2020 09:57:47 +0200 Subject: [PATCH] Implement length for lazy iterators --- src/Utilities/lazy_iterators.jl | 1 + test/Utilities/lazy_iterators.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Utilities/lazy_iterators.jl b/src/Utilities/lazy_iterators.jl index a7b44938a9..8e40030585 100644 --- a/src/Utilities/lazy_iterators.jl +++ b/src/Utilities/lazy_iterators.jl @@ -22,6 +22,7 @@ function LazyMap{T}(f::Function, data) where {T} return LazyMap{T, typeof(data)}(f, data) end Base.size(it::LazyMap) = size(it.data) +Base.length(it::LazyMap) = length(it.data) function Base.iterate(it::LazyMap, args...) elem_state = iterate(it.data, args...) if elem_state === nothing diff --git a/test/Utilities/lazy_iterators.jl b/test/Utilities/lazy_iterators.jl index 9da31338b6..0b3db20412 100644 --- a/test/Utilities/lazy_iterators.jl +++ b/test/Utilities/lazy_iterators.jl @@ -6,6 +6,7 @@ const MOIU = MOI.Utilities @testset "EmptyVector{$T}" for T in [Int, Float64] v = MOIU.EmptyVector{T}() @test size(v) == (0,) + @test length(v) == 0 @test isempty(v) @test eltype(v) == T @test iterate(v) === nothing @@ -17,6 +18,7 @@ end @testset "LazyMap{$T}" for T in [Int, Float64] v = MOIU.LazyMap{T}(x -> x^2, [2, 3]) @test size(v) == (2,) + @test length(v) == 2 @test !isempty(v) @test eltype(v) == T c = collect(v)