Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/ScopedValues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ struct ScopedFunctor{F}
end
(sf::ScopedFunctor)() = @enter_scope sf.scope sf.f()

"""
get(val::ScopedValue{T}, default::T)::T

Like the single-argument [`ScopedValues.get`](@ref), but returns the
provided `default` rather than the default in `val` and does not wrap
the return in `Some` (to save the allocation).
"""
function get(val::ScopedValue{T}, default::T) where {T}
scope = current_scope()::Union{Nothing, Scope}
scope === nothing && return default
scope = scope::Scope
return Base.get(scope.values, val, default)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ::Union{Nothing, Scope} is likely unecessary (and might even be slower).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ::Union{Nothing, Scope} is how this is called upstream. I've removed it in this PR, but which is right?


@deprecate scoped with

end # module ScopedValues
Loading