|
1 | 1 | # ZeroDimensionalArrays
|
2 | 2 |
|
3 | 3 | [](https://github.com/JuliaArrays/ZeroDimensionalArrays.jl/actions/workflows/CI.yml?query=branch%3Amain)
|
| 4 | +[](https://juliahub.com/ui/Packages/General/ZeroDimensionalArrays) |
| 5 | +[](https://juliahub.com/ui/Packages/General/ZeroDimensionalArrays?t=2) |
4 | 6 | [](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/Z/ZeroDimensionalArrays.html)
|
5 | 7 | [](https://github.com/JuliaTesting/Aqua.jl)
|
| 8 | + |
| 9 | +A small software package for the Julia programming language providing zero-dimensional array types. `Ref`-killer. |
| 10 | + |
| 11 | +Exports three zero-dimensional subtypes of `AbstractArray`: |
| 12 | +* `ZeroDimensionalArrayImmutable` |
| 13 | + * declared with `struct`, not with `mutable struct` |
| 14 | + * does not support `setfield!`, or mutating the element otherwise |
| 15 | + * `isbits` when the element is `isbits` |
| 16 | +* `ZeroDimensionalArrayMutable` |
| 17 | + * declared with `mutable struct` |
| 18 | + * supports `setfield!` |
| 19 | +* `ZeroDimensionalArrayMutableConstField` |
| 20 | + * declared with `mutable struct` |
| 21 | + * does not support `setfield!`, or mutating the element otherwise |
| 22 | + * included for completeness, but not likely to be useful often |
| 23 | + |
| 24 | +The motivation for creating this package is: |
| 25 | +* To prevent the frequent confusion regarding `Ref` vs `Base.RefValue` by offering a replacement that makes `Ref` unnecessary in many use cases. Previous discussion: |
| 26 | + * https://github.com/JuliaLang/julia/issues/38133 |
| 27 | + * https://github.com/JuliaLang/julia/issues/55321 |
| 28 | + * https://discourse.julialang.org/t/ref-is-not-a-concrete-type-poorly-documented/120375 |
| 29 | + * https://discourse.julialang.org/t/ref-t-vs-base-refvalue-t/127886/ |
| 30 | +* To provide "mutable wrapper" functionality, something `Ref` is often used for: |
| 31 | + * `ZeroDimensionalArrayMutable` can be a good replacement. Examples: |
| 32 | + * make a `const` binding that's mutable: |
| 33 | + ```julia |
| 34 | + const some_const_binding = ZeroDimensionalArrayMutable(fill(0.2)) |
| 35 | + ``` |
| 36 | + * make a field within an immutable `struct` mutable (warning: it's usually more efficient to change the entire `struct` into a `mutable struct`) |
| 37 | + ```julia |
| 38 | + struct SomeImmutableType |
| 39 | + immutable_bool::Bool |
| 40 | + immutable_float::Float64 |
| 41 | + mutable_int::ZeroDimensionalArrayMutable{Int} |
| 42 | + end |
| 43 | + ``` |
| 44 | + * previous discussion: |
| 45 | + * https://github.com/JuliaLang/julia/issues/40369 |
| 46 | + * https://discourse.julialang.org/t/dynamic-immutable-type/127168 |
| 47 | +* to provide a wrapper type for treating a value as a scalar in broadcasting, something `Ref` is often used for: |
| 48 | + * `ZeroDimensionalArrayImmutable` can be a good replacement. Construct one from its only element using the `wrap_in_0dim` function. Like this: |
| 49 | + ```julia-repl |
| 50 | + julia> using ZeroDimensionalArrays |
| 51 | +
|
| 52 | + julia> isa.(wrap_in_0dim([1,2,3]), [Array, Dict, Int]) |
| 53 | + 3-element BitVector: |
| 54 | + 1 |
| 55 | + 0 |
| 56 | + 0 |
| 57 | + ``` |
0 commit comments