Skip to content

Commit c46688c

Browse files
authored
Add DataAPI.unwrap with default definition (#35)
As discussed in JuliaData/CategoricalArrays.jl#142.
1 parent 4d8facd commit c46688c

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DataAPI"
22
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
33
authors = ["quinnj <[email protected]>"]
4-
version = "1.5.1"
4+
version = "1.6.0"
55

66
[compat]
77
julia = "1"

src/DataAPI.jl

+14
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,18 @@ struct Cols{T<:Tuple}
169169
Cols(args...) = new{typeof(args)}(args)
170170
end
171171

172+
"""
173+
unwrap(x)
174+
175+
For a given scalar argument `x`, potentially "unwrap" it to return the base wrapped value.
176+
Useful as a generic API for wrapper types when the original value is needed.
177+
178+
The default definition just returns `x` itself, i.e. no unwrapping is performned.
179+
180+
This generic function is owned by DataAPI.jl itself, which is the sole provider of the
181+
default definition.
182+
"""
183+
function unwrap end
184+
unwrap(x) = x
185+
172186
end # module

test/runtests.jl

+5
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,9 @@ end
8585

8686
end
8787

88+
@testset "unwrap" begin
89+
@test DataAPI.unwrap(1) === 1
90+
@test DataAPI.unwrap(missing) === missing
91+
end
92+
8893
end # @testset "DataAPI"

0 commit comments

Comments
 (0)