Skip to content

Commit 345ccf9

Browse files
authored
Merge pull request #9 from davidanthoff/lifting
Add support for . lifting
2 parents 5e44031 + 58ed55e commit 345ccf9

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/DataValues.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ get(x::DataValue) = isnull(x) ? throw(DataValueException()) : x.value
7878
get(x::DataValue{Union{}}) = throw(DataValueException())
7979
get(x::DataValue{Union{}}, y) = y
8080

81-
unsafe_get(x::DataValue) = x.value
82-
unsafe_get(x) = x
81+
Base.unsafe_get(x::DataValue) = x.value
8382

8483
isnull(x::DataValue) = !x.hasvalue
8584

85+
Base.hasvalue(x::DataValue) = x.hasvalue
86+
8687
const DataValuehash_seed = UInt === UInt64 ? 0x932e0143e51d0171 : 0xe51d0171
8788

8889
function hash(x::DataValue, h::UInt)
@@ -235,4 +236,6 @@ function isless{S,T}(x::DataValue{S}, y::DataValue{T})
235236
end
236237
end
237238

239+
include("broadcast.jl")
240+
238241
end

src/broadcast.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Base.Broadcast._containertype(::Type{<:DataValue}) = DataValue
2+
3+
Base.Broadcast.promote_containertype(::Type{Any}, ::Type{DataValue}) = DataValue
4+
Base.Broadcast.promote_containertype(::Type{DataValue}, ::Type{Any}) = DataValue
5+
Base.Broadcast.promote_containertype(::Type{Tuple}, ::Type{DataValue}) = Tuple
6+
Base.Broadcast.promote_containertype(::Type{DataValue}, ::Type{Tuple}) = Tuple
7+
Base.Broadcast.promote_containertype(::Type{DataValue}, ::Type{Nullable}) = DataValue
8+
Base.Broadcast.promote_containertype(::Type{Nullable}, ::Type{DataValue}) = DataValue
9+
10+
Base.Broadcast.broadcast_indices(::Type{DataValue}, A) = ()
11+
12+
Base.Broadcast._unsafe_get_eltype(x::DataValue) = eltype(x)
13+
14+
Base.Broadcast._broadcast_getindex_eltype(::Type{DataValue}, T::Type) = Type{T}
15+
Base.Broadcast._broadcast_getindex_eltype(::Type{DataValue}, A) = typeof(A)
16+
17+
Base.@propagate_inbounds Base.Broadcast._broadcast_getindex(::Type{DataValue}, A, I) = A
18+
19+
@inline function Base.Broadcast.broadcast_c(f, ::Type{DataValue}, a...)
20+
nonnull = all(Base.hasvalue, a)
21+
S = Base.Broadcast._nullable_eltype(f, a...)
22+
if isleaftype(S) && Base.null_safe_op(f, Base.Broadcast.maptoTuple(Base.Broadcast._unsafe_get_eltype,a...).types...)
23+
DataValue{S}(f(map(unsafe_get, a)...), nonnull)
24+
else
25+
if nonnull
26+
DataValue(f(map(unsafe_get, a)...))
27+
else
28+
DataValue{Base.nullable_returntype(S)}()
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)