@@ -13,38 +13,29 @@ Base.convert(::Type{<:Vector}, x::ContextManager) = [x(identity)]
1313# Const
1414# -----
1515
16- Base. convert (:: Type{<:Const} , x:: Nothing ) = Const (nothing )
1716function Base. convert (:: Type{Const} , x:: Vector )
1817 @assert ! isempty (x) " can only convert empty Vector to Nothing, got $(x) "
1918 Const ([])
2019end
2120
22- # Nothing
23- # -------
24-
25- function Base. convert (:: Type{Nothing} , x:: Vector )
26- @assert ! isempty (x) " can only convert empty Vector to Nothing, got $(x) "
27- nothing
28- end
29-
3021# Identity
3122# --------
3223
33- # Nothing and Const are just passed through when asked to convert to identity
34- # this is intended special behaviour in order for Identity + Nothing/ Const to work together as Option/Either
35- Base. convert (:: Type{Identity} , x:: Union{Nothing, Const} ) = x
24+ # Const are just passed through when asked to convert to identity
25+ # this is intended special behaviour in order for Identity + Const to work together as Option/Either
26+ Base. convert (:: Type{Identity} , x:: Const ) = x
3627# ContextManager is executed
37- Base. convert (:: Type{<:Identity} , x:: ContextManager ) = Identity (x (identity ))
28+ Base. convert (:: Type{<:Identity} , x:: ContextManager ) = Identity (run (x ))
3829
3930
4031# ContextManager
4132# --------------
4233
4334Base. convert (:: Type{<:ContextManager} , x:: Identity ) = @ContextManager cont -> cont (x. value)
4435
45- # Note that we do not support convert from Nothing/ Const to ContextManager.
36+ # Note that we do not support convert from Const to ContextManager.
4637# ContextManager is similar to Identity a Container which always contains a single element,
47- # however, unlike Identity, we cannot simply pass-through Nothing/ Const and preserve the empty container by this trick.
38+ # however, unlike Identity, we cannot simply pass-through Const and preserve the empty container by this trick.
4839# To map over ContextManager, you NEED to create a new ContextManager, if you don't want to run the contextmanager
4940# immediately. Hence, also flatmap needs to create another ContextManager, i.e. single element container.
5041
@@ -69,8 +60,8 @@ Base.convert(::Type{Option}, x::Option) = x
6960
7061Base. convert (:: Type{Option{T}} , x:: Identity ) where T = Identity (Base. convert (T, x))
7162Base. convert (:: Type{Option{T}} , x:: Identity{T} ) where T = x # nothing to convert
72- Base. convert (:: Type{Option{T}} , x:: Nothing ) where T = x # nothing to convert
73- Base. convert (:: Type{Option} , x:: Nothing ) = x # nothing to convert
63+ Base. convert (:: Type{Option{T}} , x:: Const{ Nothing} ) where T = x # nothing to convert
64+ Base. convert (:: Type{Option} , x:: Const{ Nothing} ) = x # nothing to convert
7465Base. convert (:: Type{Option} , x:: Identity ) = x # nothing to convert
7566
7667
@@ -86,21 +77,3 @@ Base.convert(::Type{Either{<:Any, R}}, x::Identity) where {R} = Identity(Base.co
8677Base. convert (:: Type{Either{<:Any, R}} , x:: Identity{R} ) where {R} = x # nothing to convert
8778Base. convert (:: Type{Either{L, <:Any}} , x:: Const ) where {L} = Const (Base. convert (L, x. value))
8879Base. convert (:: Type{Either{L, <:Any}} , x:: Const{L} ) where {L} = x # nothing to convert
89-
90-
91- # OptionEither
92- # ------------
93-
94- Base. convert (:: Type{OptionEither{L, R}} , x:: Identity ) where {L, R} = Identity (Base. convert (R, x. value))
95- Base. convert (:: Type{OptionEither{L, R}} , x:: Identity{R} ) where {L, R} = x # nothing to convert
96- Base. convert (:: Type{OptionEither{L, R}} , x:: Const ) where {L, R} = Const (Base. convert (L, x. value))
97- Base. convert (:: Type{OptionEither{L, R}} , x:: Const{L} ) where {L, R} = x # nothing to convert
98-
99- Base. convert (:: Type{OptionEither{<:Any, R}} , x:: Identity ) where {R} = Identity (Base. convert (R, x. value))
100- Base. convert (:: Type{OptionEither{<:Any, R}} , x:: Identity{R} ) where {R} = x # nothing to convert
101- Base. convert (:: Type{OptionEither{L, <:Any}} , x:: Const ) where {L} = Const (Base. convert (L, x. value))
102- Base. convert (:: Type{OptionEither{L, <:Any}} , x:: Const{L} ) where {L} = x # nothing to convert
103-
104- Base. convert (:: Type{OptionEither{L, R}} , x:: Nothing ) where {L, R} = x # nothing to convert
105- Base. convert (:: Type{OptionEither} , x:: Nothing ) = x # nothing to convert
106- Base. convert (:: Type{OptionEither} , x:: Identity ) = x # nothing to convert
0 commit comments