Skip to content
Merged
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
2 changes: 1 addition & 1 deletion examples/primes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end # hide
using Transducers

sieve(xf, x) =
if mapfoldl(xf, right, (x,), init=nothing) === nothing
if isnothing(mapfoldl(xf, right, (x,), init=nothing))
nothing, xf
else
x, xf |> Filter(n -> n % x != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ Base.show(io::IO, init::CopyInit) = _default_show(io, init)
@inline foldlargs(op, x) = x
@inline foldlargs(op, x1, x2, xs...) =
foldlargs(op,
@return_if_reduced(op(x1, x2)),
@next(op, x1, x2),
xs...)

"""
Expand Down
3 changes: 3 additions & 0 deletions src/processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ end
return complete(rf, val)
end

__foldl__(rf, init, coll::Tuple) =
complete(rf, @return_if_reduced foldlargs(rf, init, coll...))

# TODO: use IndexStyle
@inline function __foldl__(rf, init, arr::Union{AbstractArray, Broadcasted})
isempty(arr) && return complete(rf, init)
Expand Down
10 changes: 10 additions & 0 deletions test/test_inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,22 @@ end
end
end

hasnothing(xs) = foreach(Map(identity), xs) do x
if x === nothing
return reduced(Val(true))
end
end |> ifunreduced() do _
Val(false)
end

@testset "foreach" begin
@testset for xs in collections
@test_inferred foreach(constant(nothing), Map(exp), xs)
@test_inferred foreach(constant(nothing), Map(exp) |> Filter(x -> x > 0),
xs)
end
@test (@inferred hasnothing((1, 2, 3))) === Val(false)
@test (@inferred hasnothing((1, nothing, 3))) === Val(true)
end

@testset "eduction" begin
Expand Down