Skip to content

Commit 70a2536

Browse files
committed
Add Utils.unwrap
1 parent f7b4508 commit 70a2536

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Utils.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,11 @@ function sort_by_creation_time(files)
412412
return sort(files, by = x -> stat(x).ctime)
413413
end
414414

415+
"""
416+
unwrap(x::Val{N})
417+
418+
Unwrap the value in `Val{N}` to get the value at runtime.
419+
"""
420+
unwrap(x::Val{N}) where {N} = N
421+
415422
end

test/utils.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import ClimaUtilities.Utils:
1212
bounding_dates,
1313
period_to_seconds_float,
1414
unique_periods,
15-
sort_by_creation_time
15+
sort_by_creation_time,
16+
unwrap
1617

1718
@testset "searchsortednearest" begin
1819
A = 10 * collect(range(1, 10))
@@ -170,4 +171,12 @@ end
170171
sorted_files = sort_by_creation_time(files)
171172
@test sorted_files == [files[2], files[3], files[1]]
172173
end
174+
175+
@testset "unwrap" begin
176+
x = Val(2)
177+
y = Val(3)
178+
@test unwrap(x) == 2
179+
@test unwrap(y) == 3
180+
end
181+
173182
end

0 commit comments

Comments
 (0)