Skip to content

Commit a95bb43

Browse files
fixing and simplifying uses of Const and Identity constructors
1 parent 269b555 commit a95bb43

6 files changed

Lines changed: 11 additions & 10 deletions

File tree

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
10+
### Fixed
11+
- `Option(3)` works now
12+
- The constructors `Const{ElementType}(value)` and `Identity{ElementType}(value)` had been removed already, however were still used. Maybe this now gave errors because of newer julia version, don't know, but now everything uses `Const(value)` and `Identity(value)` instead.
913
## [1.0.0] - 2020-07-19
1014
### Added
1115
- CI via GitHubActions

src/Const.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Iterators.flatten(c::Const) = c
3838
Base.eltype(::Type{<:Const}) = Any
3939

4040
Base.convert(::Type{Const{T}}, x::Const{T}) where {T} = x
41-
Base.convert(::Type{Const{T}}, x::Const) where {T} = Const{T}(convert(T, x.value))
41+
Base.convert(::Type{Const{T}}, x::Const) where {T} = Const(convert(T, x.value))
4242

4343
# Const is covariate
4444
# promote_rule only works on concrete types, more general checks Type{<:Const} may overwrite

src/Identity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Base.map(f, a::Identity) = Identity(f(a.value))
4242
Base.Iterators.flatten(a::Identity) = convert(Identity, a.value)
4343

4444
Base.convert(::Type{Identity{T}}, x::Identity{T}) where {T} = x
45-
Base.convert(::Type{Identity{T}}, x::Identity) where {T} = Identity{T}(convert(T, x.value))
45+
Base.convert(::Type{Identity{T}}, x::Identity) where {T} = Identity(convert(T, x.value))
4646

4747
# Identity is covariate
4848
# promote_rule only works on concrete types, more general checks Type{<:Const} may overwrite

src/Option.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ We reuse [`Identity`](@ref) as representing the single-element-container and `Co
1515
"""
1616
const Option{T} = Union{Const{Nothing}, Identity{T}}
1717

18-
Option{T}(::Nothing) where T = Const(nothing)
19-
Option{T}(a::T) where T = Identity{T}(a)
2018
Option(::Nothing) = Const(nothing)
21-
Option(a::T) where T = Identity{T}(a)
22-
Option{T}() where T = Const(nothing)
19+
Option(a) = Identity(a)
2320
Option() = Const(nothing)
2421

2522

test/Const.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ end) == ""
2323

2424
@test Iterators.flatten(Const(5)) == Const(5)
2525

26-
@test convert(Const{Float32}, Const(1)) == Const{Float32}(Float32(1))
27-
@test convert(Const{Number}, Const(1)) == Const{Number}(1)
26+
@test convert(Const{Float32}, Const(1)) == Const(Float32(1))
27+
@test convert(Const{Number}, Const(1)) == Const(1)
2828

2929
@test promote_type(Const{Int}, Const{Number}) == Const{Number}
3030
@test promote_type(Const{Int}, Const{String}) == Const

test/Identity.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ end == Identity(3 + 4)
2929
print(5)
3030
end) == "5"
3131

32-
@test convert(Identity{Float32}, Identity(1)) == Identity{Float32}(Float32(1))
33-
@test convert(Identity{Number}, Identity(1)) == Identity{Number}(1)
32+
@test convert(Identity{Float32}, Identity(1)) == Identity(Float32(1))
33+
@test convert(Identity{Number}, Identity(1)) == Identity(1)
3434

3535
@test promote_type(Identity{Int}, Identity{Number}) == Identity{Number}
3636
@test promote_type(Identity{Int}, Identity{String}) == Identity

0 commit comments

Comments
 (0)