Skip to content

disberd/MutableScopedValues.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MutableScopedValues

Build Status Coverage

This package introduces the MutableScopedValue type which combines a RefValue and a ScopedValue. It aims to have the basic functionality of a ScopedValue but allow to also change it's value persistently outside of ScopedValues.with blocks.

It also defines a custom with method to allow mixing ScopedValues and MutableScopedValues within the same with call

This repo was initially named ScopedRefValues but was modified after the feeedback in https://discourse.julialang.org/t/change-scopedvalue-default-outside-of-with/130631

Examples

julia> using MutableScopedValues

julia> sv = MutableScopedValue{Float64}(3.0);

julia> sv[]
3.0

julia> sv[] = 5
5

julia> sv[]
5.0

julia> with(() -> sv[], sv => 1.0) # Setting with `with` has precedence over `setindex!`
1.0

See the docstring for more details

About

Like ScopedValue, but with the possibility of changing it's default value persistently

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages