Redis.jl returns nothing when requesting a the value of a key that doesn't exist:
using Redis conn = RedisConnection() r = get(conn, "non_existent_key") disconnect(conn) r == nothing # true On Sunday, March 20, 2016 at 1:31:30 AM UTC+11, Milan Bouchet-Valat wrote: > > For now I don't know of a good solution to this pattern, but there's > been some discussion about it: > https://github.com/JuliaLang/julia/issues/15174 > > You should definitely use a Nullable instead of returning nothing. > > > Regards > > Le samedi 19 mars 2016 à 02:58 -0700, Jeffrey Sarnoff a écrit : > > You may be misusing nothing. It is unusual that a function would > > return nothing some of the time and something other times. > > Take a look at http://docs.julialang.org/en/latest/manual/faq/#nothin > > gness-and-missing-values > > If you have additional questions about this, please give an example > > of what get_a(...) is getting and why it would be nothing some of the > > time. > > > > > Hi All > > > > > > > > > I found my self writing code like this a lot: > > > > > > x = get_a(...) > > > > > > if x != nothing > > > y::A = x > > > do_sth(y, ...) > > > end > > > > > > In the above, I have to check for nothing first, and if it is not > > > nothing, then I do a type assert to make sure the type is what I > > > expected. > > > > > > Is there any function or macro in Julia that can help this? > > > > > > I know in F#, I have option.bind, so option.bind f x is equivalent > > > to a pattern match: if x is None - > None; if x is something -> > > > f(something) > > > > > > Also in C#, I have "customers?[0]?.Orders?.Count();" (as long as > > > there is null before ?, it returns null immediately) > > > > > > Does Julia have something similar? > > > > > > >
