https://github.com/juliafolds/microcollections.jl
Immutable empty and singleton collections
https://github.com/juliafolds/microcollections.jl
arrays data-structures dictionaries immutable julia sets
Last synced: about 2 months ago
JSON representation
Immutable empty and singleton collections
- Host: GitHub
- URL: https://github.com/juliafolds/microcollections.jl
- Owner: JuliaFolds
- License: mit
- Created: 2020-05-30T21:04:56.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T10:06:39.000Z (about 2 years ago)
- Last Synced: 2024-05-10T06:10:46.401Z (12 months ago)
- Topics: arrays, data-structures, dictionaries, immutable, julia, sets
- Language: Julia
- Homepage:
- Size: 305 KB
- Stars: 12
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MicroCollections
[](https://juliafolds.github.io/MicroCollections.jl/dev)
[](https://github.com/JuliaFolds/MicroCollections.jl/actions?query=workflow%3A%22Run+tests%22)MicroCollections.jl provides immutable empty and singleton collections.
```julia
julia> using MicroCollectionsjulia> vec0() # or EmptyVector()
0-element EmptyVector{Union{}}julia> vec0(Int) # or EmptyVector{Int}()
0-element EmptyVector{Int64}julia> vec1(1) # or SingletonVector((1,))
1-element SingletonVector{Int64}:
1julia> EmptyDict()
EmptyDict{Union{},Union{}}()julia> EmptyDict{Symbol,Char}()
EmptyDict{Symbol,Char}()julia> SingletonDict(:a => 0)
SingletonDict{Symbol,Int64} with 1 entry:
:a => 0julia> EmptySet()
EmptySet{Union{}}()julia> EmptySet{Int64}()
EmptySet{Int64}()julia> SingletonSet((1,))
SingletonSet{Int64} with 1 element:
1
```With BangBang.jl, MicroCollections.jl is useful for constructing
singleton solutions that can be combined with a reduce:```julia
julia> using BangBang.Experimental: mergewith!!julia> @assert mapreduce(
x -> SingletonDict(abs(x) % 10 => 1), mergewith!!(+), 1:1000,
) == Dict(
0 => 100,
1 => 100,
2 => 100,
3 => 100,
4 => 100,
5 => 100,
6 => 100,
7 => 100,
8 => 100,
9 => 100,
)
```