Skip to content

Commit 888006b

Browse files
committed
Define length(::SkipMissing)
1 parent 9d70d45 commit 888006b

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Standard library changes
4343
------------------------
4444
* The `nextprod` function now accepts tuples and other array types for its first argument ([#35791]).
4545
* The function `isapprox(x,y)` now accepts the `norm` keyword argument also for numeric (i.e., non-array) arguments `x` and `y` ([#35883]).
46+
* `length` now supports `SkipMissing`-wrapped containers ([#35946]).
4647

4748
#### LinearAlgebra
4849

base/missing.jl

+7
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ keys(itr::SkipMissing) =
258258
v === missing && throw(MissingException("the value at index $I is missing"))
259259
v
260260
end
261+
function length(itr::SkipMissing)
262+
i = 0
263+
for _ in itr
264+
i += 1
265+
end
266+
return i
267+
end
261268

262269
function show(io::IO, s::SkipMissing)
263270
print(io, "skipmissing(")

test/missing.jl

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ end
363363
@testset "skipmissing" begin
364364
x = skipmissing([1, 2, missing, 4])
365365
@test eltype(x) === Int
366+
@test length(x) == 3
366367
@test collect(x) == [1, 2, 4]
367368
@test collect(x) isa Vector{Int}
368369

0 commit comments

Comments
 (0)