Skip to content

Commit 9af8889

Browse files
S. SahmS. Sahm
authored andcommitted
a few fixes, and added Nothing
1 parent 4166209 commit 9af8889

5 files changed

Lines changed: 16 additions & 40 deletions

File tree

src/DataTypesBasic.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export Const, Identity,
3737

3838
using IsDef
3939

40+
include("Nothing.jl")
4041
include("Const.jl")
4142
include("Identity.jl")
4243
include("Option.jl")

src/Either.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Base.typejoin(::Type{<:Either}, ::Type{<:Either}) = Either
3030
Base.convert(::Type{Either{L, R}}, x::Identity) where {L, R} = Identity(Base.convert(R, x.value))
3131
Base.convert(::Type{Either{L, R}}, x::Const) where {L, R} = Const(Base.convert(L, x.value))
3232

33-
Base.eltype(::Type{<:Either{L, R}}) where {L, R} = R
34-
Base.eltype(::Type{<:Either{<:Any, R}}) where {R} = R
35-
Base.eltype(::Type{<:Either}) = Any
33+
Base.eltype(::Type{Either{L, R}}) where {L, R} = R
34+
Base.eltype(::Type{Either{<:Any, R}}) where {R} = R
35+
Base.eltype(::Type{Either}) = Any
3636

3737

3838
# Helpers for Either

src/Nothing.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Base.iterate(::Nothing) = nothing
2+
Base.foreach(f, ::Nothing) = nothing
3+
Base.map(f, ::Nothing) = nothing
4+
Iterators.flatten(::Nothing) = nothing
5+
6+
7+
# we need this for safety, if someone overwrites typejoin for Unions with Const
8+
Base.typejoin(::Type{Nothing}, ::Type{Nothing}) = Nothing

src/Option.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Base.hash(a::Some) = hash(a.value)
3131
# [2] convert(::Type{Union{Nothing, Some{T}} where T}, ::Int64) at ./some.jl:34
3232
# [3] top-level scope at none:0
3333
# importantly, we should only add clauses for Type{Option} and not Type{<:Option} to not interfere with existing code
34-
Base.convert(::Type{Option}, x) = throw(MethodError(Base.convert, (Option, x)))
3534
Base.convert(::Type{Option}, x::Option) = x
3635
# Option{T} seems to be already covered by normal Union, Some, Nothing conversions, no need to provide them
3736

@@ -51,6 +50,5 @@ end
5150
issomething(m::Nothing) = false
5251
issomething(m::Identity) = true
5352

54-
# Base.eltype is not well defined for Some, and always returns Any
55-
Base.eltype(::Type{<:Option{T}}) where {T} = T
56-
Base.eltype(::Type{Nothing}) = Any # if we don't provide this clause, we get ERROR: UndefVarError: T not defined, as the above clause matches, but no T can be infered from Nothing
53+
Base.eltype(::Type{Option{T}}) where {T} = T
54+
Base.eltype(::Type{Option}) = Any

src/Try.jl

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -81,35 +81,6 @@ Base.convert(::Type{Try{T}}, x::Identity{S}) where {S, T} = Identity(Base.conver
8181
promote_rule(::Type{Try{T}}, ::Type{Try{S}}) where {T, S<:T} = Try{T}
8282

8383

84-
85-
# typejoin Thrown & Thrown
86-
# Base.typejoin(::Type{Thrown{E}}, ::Type{Thrown{E}}) where E = Thrown{E}
87-
# Base.typejoin(::Type{<:Thrown}, ::Type{<:Thrown}) = Thrown
88-
# # typejoin Identity & Identity
89-
# Base.typejoin(::Type{Identity{T}}, ::Type{Identity{T}}) where T = Identity{E}
90-
# Base.typejoin(::Type{<:Identity}, ::Type{<:Identity}) = Identity
91-
# # typejoin Thrown & Identity
92-
# Base.typejoin(::Type{Thrown{E}}, ::Type{Identity{T}}) where {T, E} = Try{T, E}
93-
# Base.typejoin(::Type{Identity{T}}, ::Type{Thrown{E}}) where {T, E} = Try{T, E}
94-
# # typejoin Thrown & Try
95-
# Base.typejoin(::Type{Thrown{E}}, ::Type{<:Try{T, E}}) where {T, E} = Try{T, E}
96-
# Base.typejoin(::Type{<:Try{T, E}}, ::Type{Thrown{E}}) where {T, E} = Try{T, E}
97-
# Base.typejoin(::Type{<:Thrown}, ::Type{<:Try{T}}) where T = Try{T}
98-
# Base.typejoin(::Type{<:Try{T}}, ::Type{<:Thrown}) where T = Try{T}
99-
# # typejoin Identity & Try
100-
# Base.typejoin(::Type{Identity{T}}, ::Type{<:Try{T, E}}) where {T, E} = Try{T, E}
101-
# Base.typejoin(::Type{<:Try{T, E}}, ::Type{Identity{T}}) where {T, E} = Try{T, E}
102-
# Base.typejoin(::Type{<:Identity}, ::Type{<:Try{<:Any, E}}) where E = Try{<:Any, E}
103-
# Base.typejoin(::Type{<:Try{<:Any, E}}, ::Type{<:Identity}) where E = Try{<:Any, E}
104-
# # typejoin Try & Try
105-
# Base.typejoin(::Type{<:Try{T, E}}, ::Type{<:Try{T, E}}) where {T, E} = Try{T, E}
106-
# Base.typejoin(::Type{<:Try{T}}, ::Type{<:Try{T}}) where {T} = Try{T}
107-
# Base.typejoin(::Type{<:Try{<:Any, E}}, ::Type{<:Try{<:Any, E}}) where {E} = Try{<:Any, E}
108-
# Base.typejoin(::Type{<:Try}, ::Type{<:Try}) = Try
109-
110-
111-
112-
11384
# we use a macro instead of dispatching on Try(f::Function) as this interferes e.g. with mapn
11485
# (in mapn anonymous functions are passed through, which should not get executed automatically)
11586
macro Try(expr)
@@ -145,7 +116,5 @@ issuccess(::Const{<:Exception}) = false
145116
isexception(::Identity) = false
146117
isexception(::Const{<:Exception}) = true
147118

148-
Base.eltype(::Type{<:Try{T}}) where T = T
149-
Base.eltype(::Type{<:Try}) = Any
150-
# somehow the normal Const eltype got broken
151-
Base.eltype(::Type{<:Const{<:Exception}}) = Any
119+
Base.eltype(::Type{Try{T}}) where T = T
120+
Base.eltype(::Type{Try}) = Any

0 commit comments

Comments
 (0)