Skip to content

Commit 3cc28ec

Browse files
committed
adds map for Nullable
1 parent 4814557 commit 3cc28ec

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

base/nullable.jl

+6
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ function hash(x::Nullable, h::UInt)
5656
return hash(x.value, h + nullablehash_seed)
5757
end
5858
end
59+
60+
# Specialised map over Nullable
61+
function map(f::Callable, x :: Nullable)
62+
isnull(x) && return Nullable{Union()}()
63+
Nullable(f(get(x)))
64+
end

test/nullable.jl

+4
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,7 @@ for T in types
243243
@test !isnull(x1.v)
244244
@test get(x1.v, one(T)) === one(T)
245245
end
246+
247+
# test map
248+
@test map(x->x, Nullable{Union()}()) === Nullable{Union()}()
249+
@test map(x->x, Nullable(1.0)) === Nullable(1.0)

0 commit comments

Comments
 (0)