Skip to content

Commit

Permalink
Allow arbitrary callable f in Empty(f)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Dec 17, 2019
1 parent ac190bc commit d587798
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/NoBang/emptycontainers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ julia> Base.IteratorEltype(Empty)
Base.HasEltype()
```
"""
struct Empty{T} end
Empty(T::Type) = Empty{T}()

push(::Empty{T}, x) where T = singletonof(T, x)
append(::Empty{T}, x) where T = T(x)
# In `append`, it is assumed that `T(x::Vector)` works (as done in the
struct Empty{T}
f::T
Empty{T}(f) where T = new(f)
end
Empty(T::Type) = Empty{Type{T}}(T)
Empty(f::T) where T = Empty{T}(f)

push(E::Empty, x) = E.f(SingletonVector(x))
append(E::Empty, x) = E.f(x)
# It is assumed that `E.f(x::Vector)` works (as done in the
# implementation of `singletonof`).

Base.IteratorSize(::Type{<:Empty}) = Base.HasLength()
Expand Down

0 comments on commit d587798

Please sign in to comment.