Skip to content

Commit

Permalink
Adjoin identity for Scan
Browse files Browse the repository at this point in the history
Without adjoin the identity, it's not possible to start `Scan` with a
custom reducing function.  So, when the user doesn't specify `init`,
let's assume that it's OK to automatically adjoin identity.
  • Loading branch information
tkf committed Jul 25, 2020
1 parent a444222 commit c37f2e3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/library.jl
Expand Up @@ -1184,7 +1184,7 @@ struct Scan{F, T} <: Transducer
init::T
end

Scan(f) = Scan(f, Init) # TODO: DefaultInit?
Scan(f) = Scan(_asmonoid(f), Init) # TODO: DefaultInit?

isexpansive(::Scan) = false

Expand Down
1 change: 1 addition & 0 deletions test/test_library.jl
Expand Up @@ -46,6 +46,7 @@ end
@testset for xs in iterator_variants(1:10)
xs isa Base.Generator && continue
@test collect(Scan(+), xs) == cumsum(xs)
@test collect(Scan((a, b) -> a + b), xs) == cumsum(xs)
end

xs0 = [0, -1, 3, -2, 1]
Expand Down

0 comments on commit c37f2e3

Please sign in to comment.