Skip to content

Commit 4793e88

Browse files
kshyatttkelman
authored andcommitted
Add doctest example for fill! (#19422)
* Add doctest example for fill! * Add more doctests
1 parent 55b1230 commit 4793e88

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

base/docs/helpdb/Base.jl

+23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ systemerror
1515
Fill array `A` with the value `x`. If `x` is an object reference, all elements will refer to
1616
the same object. `fill!(A, Foo())` will return `A` filled with the result of evaluating
1717
`Foo()` once.
18+
19+
```jldoctest
20+
julia> A = zeros(2,3)
21+
2×3 Array{Float64,2}:
22+
0.0 0.0 0.0
23+
0.0 0.0 0.0
24+
25+
julia> fill!(A, 2.)
26+
2×3 Array{Float64,2}:
27+
2.0 2.0 2.0
28+
2.0 2.0 2.0
29+
30+
julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(3), a); a[1] = 2; A
31+
3-element Array{Array{Int64,1},1}:
32+
[2,1,1]
33+
[2,1,1]
34+
[2,1,1]
35+
36+
julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(3), f())
37+
1
38+
1
39+
1
40+
```
1841
"""
1942
fill!
2043

0 commit comments

Comments
 (0)