File tree 4 files changed +100
-8
lines changed
4 files changed +100
-8
lines changed Original file line number Diff line number Diff line change @@ -1466,13 +1466,6 @@ julia> log2(10)
1466
1466
"""
1467
1467
log2
1468
1468
1469
- """
1470
- isnull(x)
1471
-
1472
- Is the `Nullable` object `x` null, i.e. missing a value?
1473
- """
1474
- isnull
1475
-
1476
1469
"""
1477
1470
abs2(x)
1478
1471
Original file line number Diff line number Diff line change @@ -1324,6 +1324,7 @@ export
1324
1324
1325
1325
# nullable types
1326
1326
isnull,
1327
+ unsafe_get,
1327
1328
1328
1329
# Macros
1329
1330
# parser internal
Original file line number Diff line number Diff line change 61
61
62
62
get (x:: Nullable ) = isnull (x) ? throw (NullException ()) : x. value
63
63
64
+ """
65
+ unsafe_get(x)
66
+
67
+ Return the value of `x` for [`Nullable`](:obj:`Nullable`) `x`; return `x` for
68
+ all other `x`.
69
+
70
+ This method does not check whether or not `x` is null before attempting to
71
+ access the value of `x` for `x::Nullable` (hence "unsafe").
72
+
73
+ ```jldoctest
74
+ julia> x = Nullable(1)
75
+ Nullable{Int64}(1)
76
+
77
+ julia> unsafe_get(x)
78
+ 1
79
+
80
+ julia> x = Nullable{String}()
81
+ Nullable{String}()
82
+
83
+ julia> unsafe_get(x)
84
+ ERROR: UndefRefError: access to undefined reference
85
+ in unsafe_get(::Nullable{String}) at ./REPL[4]:1
86
+
87
+ julia> x = 1
88
+ 1
89
+
90
+ julia> unsafe_get(x)
91
+ 1
92
+ ```
93
+ """
94
+ unsafe_get (x:: Nullable ) = x. value
95
+ unsafe_get (x) = x
96
+
97
+ """
98
+ isnull(x)
99
+
100
+ Return whether or not `x` is null for [`Nullable`](:obj:`Nullable`) `x`; return
101
+ `false` for all other `x`.
102
+
103
+ ```jldoctest
104
+ julia> x = Nullable(1, false)
105
+ Nullable{Int64}(1)
106
+
107
+ julia> isnull(x)
108
+ false
109
+
110
+ julia> x = Nullable(1, true)
111
+ Nullable{Int64}()
112
+
113
+ julia> isnull(x)
114
+ true
115
+
116
+ julia> x = 1
117
+ 1
118
+
119
+ julia> isnull(x)
120
+ false
121
+ ```
122
+ """
123
+ isnull (x:: Nullable ) = x. isnull
124
+ isnull (x) = false
125
+
64
126
isnull (x:: Nullable ) = ! x. hasvalue
65
127
66
128
# # Operators
Original file line number Diff line number Diff line change @@ -161,15 +161,51 @@ for T in types
161
161
@test get (x3, zero (T)) === one (T)
162
162
end
163
163
164
- # isnull(x::Nullable)
165
164
for T in types
165
+ # unsafe_get(x::Nullable)
166
+ x1 = Nullable {T} ()
167
+ x2 = Nullable (zero (T))
168
+ x3 = Nullable (one (T))
169
+ a = rand (T)
170
+ x4 = Nullable (a)
171
+
172
+ @test isa (unsafe_get (x1), T)
173
+ @test unsafe_get (x2) === zero (T)
174
+ @test unsafe_get (x3) === one (T)
175
+ @test unsafe_get (x4) === a
176
+
177
+ # unsafe_get(x)
178
+ x2 = zero (T)
179
+ x3 = one (T)
180
+ x4 = rand (T)
181
+
182
+ @test unsafe_get (x2) === zero (T)
183
+ @test unsafe_get (x3) === one (T)
184
+ @test unsafe_get (x4) === x4
185
+ end
186
+
187
+ @test_throws UndefRefError unsafe_get (Nullable ())
188
+ @test_throws UndefRefError unsafe_get (Nullable {String} ())
189
+ @test_throws UndefRefError unsafe_get (Nullable {Array} ())
190
+
191
+ for T in types
192
+ # isnull(x::Nullable)
166
193
x1 = Nullable {T} ()
167
194
x2 = Nullable (zero (T))
168
195
x3 = Nullable (one (T))
169
196
170
197
@test isnull (x1) === true
171
198
@test isnull (x2) === false
172
199
@test isnull (x3) === false
200
+
201
+ # isnull(x)
202
+ x1 = zero (T)
203
+ x2 = one (T)
204
+ x3 = rand (T)
205
+
206
+ @test isnull (x1) === false
207
+ @test isnull (x2) === false
208
+ @test isnull (x3) === false
173
209
end
174
210
175
211
@test isnull (Nullable ())
You can’t perform that action at this time.
0 commit comments