diff --git a/Project.toml b/Project.toml index 7bfdc9d..103aae3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ParameterHandling" uuid = "2412ca09-6db7-441c-8e3a-88d5709968c5" authors = ["Invenia Technical Computing Corporation"] -version = "0.4.7" +version = "0.4.8" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/flatten.jl b/src/flatten.jl index 82d5b60..1414cb0 100644 --- a/src/flatten.jl +++ b/src/flatten.jl @@ -19,9 +19,15 @@ function flatten end flatten(x) = flatten(Float64, x) +function flatten(::Type{T}, ::Nothing) where {T<:Real} + v = T[] + unflatten_to_Nothing(::Vector{T}) = nothing + return v, unflatten_to_Nothing +end + function flatten(::Type{T}, x::Integer) where {T<:Real} v = T[] - unflatten_to_Integer(v::Vector{T}) = x + unflatten_to_Integer(::Vector{T}) = x return v, unflatten_to_Integer end diff --git a/test/flatten.jl b/test/flatten.jl index 47f4707..6b15e42 100644 --- a/test/flatten.jl +++ b/test/flatten.jl @@ -8,6 +8,11 @@ end end + @testset "Nothing" begin + test_flatten_interface(nothing) + @test isempty(first(flatten(nothing))) + end + @testset "AbstractArrays" begin test_flatten_interface(randn(10)) test_flatten_interface(randn(5, 4))