Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a better example for get!(f::Function, collection, key) #36964

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Changes from all commits
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
25 changes: 19 additions & 6 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,25 @@ get!(collection, key, default)
Return the value stored for the given key, or if no mapping for the key is present, store
`key => f()`, and return `f()`.

This is intended to be called using `do` block syntax:
```julia
get!(dict, key) do
# default value calculated here
time()
end
This is intended to be called using `do` block syntax.

# Examples
```jldoctest
julia> squares = Dict{Int,Int}();

julia> function get_square!(d, i)
get!(d, i) do
i^2
end
end
get_square! (generic function with 1 method)

julia> get_square!(squares, 2)
4

julia> squares
Dict{Int64,Int64} with 1 entry:
2 => 4
```
"""
get!(f::Function, collection, key)
Expand Down