Skip to content

Commit

Permalink
Add Empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 5, 2019
1 parent fe3a999 commit f422fa4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/BangBang.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module BangBang
@doc read(joinpath(dirname(@__DIR__), "README.md"), String) BangBang

export @!,
Empty,
append!!,
delete!!,
empty!!,
Expand Down Expand Up @@ -33,7 +34,7 @@ function ismutable end
function push!! end

include("NoBang/NoBang.jl")
using .NoBang: ImmutableContainer, singletonof
using .NoBang: Empty, ImmutableContainer, singletonof

include("core.jl")
include("base.jl")
Expand Down
3 changes: 2 additions & 1 deletion src/NoBang/NoBang.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module NoBang

export singletonof
export Empty, singletonof

using Base.Iterators: Pairs
using Base: ImmutableDict
Expand All @@ -17,6 +17,7 @@ include("singletoncontainers.jl")
include("base.jl")
include("linearalgebra.jl")
include("singletonof.jl")
include("emptycontainers.jl")

function __init__()
@require StaticArrays="90137ffa-7385-5640-81b9-e52037218182" begin
Expand Down
35 changes: 35 additions & 0 deletions src/NoBang/emptycontainers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Empty(T)
Create a proxy of an empty container of type `T`.
# Examples
```jldoctest
julia> using BangBang
julia> push!!(Empty(Vector), 1)
1-element Array{Int64,1}:
1
julia> append!!(Empty(Dict), (:a=>1, :b=>2))
Dict{Symbol,Int64} with 2 entries:
:a => 1
:b => 2
julia> using DataFrames: DataFrame
julia> @assert push!!(Empty(DataFrame), (a=1, b=2)) == DataFrame(a=[1], b=[2])
julia> using StructArrays: StructVector
julia> @assert push!!(Empty(StructVector), (a=1, b=2)) == StructVector(a=[1], b=[2])
julia> using TypedTables: Table
julia> @assert push!!(Empty(Table), (a=1, b=2)) == Table(a=[1], b=[2])
```
"""
struct Empty{T} end
Empty(T::Type) = Empty{T}()

push(::Empty{T}, x) where T = singletonof(T, x)

0 comments on commit f422fa4

Please sign in to comment.