Skip to content

Commit

Permalink
Move docs inline from helpdb/Base.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
xorJane committed Dec 22, 2016
1 parent 5989eaf commit 0eb1f47
Show file tree
Hide file tree
Showing 16 changed files with 552 additions and 605 deletions.
30 changes: 30 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,41 @@ _length(A) = length(A)
endof(a::AbstractArray) = length(a)
first(a::AbstractArray) = a[first(eachindex(a))]

"""
first(coll)
Get the first element of an iterable collection. Returns the start point of a
`Range` even if it is empty.
```jldoctest
julia> first(2:2:10)
2
julia> first([1; 2; 3; 4])
1
```
"""
function first(itr)
state = start(itr)
done(itr, state) && throw(ArgumentError("collection must be non-empty"))
next(itr, state)[1]
end

"""
last(coll)
Get the last element of an ordered collection, if it can be computed in O(1) time. This is
accomplished by calling [`endof`](@ref) to get the last index. Returns the end
point of a `Range` even if it is empty.
```jldoctest
julia> last(1:2:10)
9
julia> last([1; 2; 3; 4])
4
```
"""
last(a) = a[end]

"""
Expand Down
12 changes: 9 additions & 3 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,15 @@ fill(v, dims::Integer...) = fill!(Array{typeof(v)}(dims...), v)

for (fname, felt) in ((:zeros,:zero), (:ones,:one))
@eval begin
($fname)(T::Type, dims...) = fill!(Array{T}(dims...), ($felt)(T))
($fname)(dims...) = fill!(Array{Float64}(dims...), ($felt)(Float64))
($fname){T}(A::AbstractArray{T}) = fill!(similar(A), ($felt)(T))
# allow signature of similar
$fname(a::AbstractArray, T::Type, dims::Tuple) = fill!(similar(a, T, dims), $felt(T))
$fname(a::AbstractArray, T::Type, dims...) = fill!(similar(a,T,dims...), $felt(T))
$fname(a::AbstractArray, T::Type=eltype(a)) = fill!(similar(a,T), $felt(T))

$fname(T::Type, dims::Tuple) = fill!(Array{T}(Dims(dims)), $felt(T))
$fname(dims::Tuple) = ($fname)(Float64, dims)
$fname(T::Type, dims...) = $fname(T, dims)
$fname(dims...) = $fname(dims)
end
end

Expand Down
17 changes: 17 additions & 0 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,23 @@ function (|)(B::BitArray, x::Bool)
end
(|)(x::Bool, B::BitArray) = B | x

"""
xor(x, y)
⊻(x, y)
Bitwise exclusive or of `x` and `y`. The infix operation
`a ⊻ b` is a synonym for `xor(a,b)`, and
`⊻` can be typed by tab-completing `\\xor`
or `\\veebar` in the Julia REPL.
```jldoctest
julia> [true; true; false] ⊻ [true; false; false]
3-element Array{Bool,1}:
false
true
false
```
"""
function xor(B::BitArray, x::Bool)
x ? ~B : copy(B)
end
Expand Down
17 changes: 17 additions & 0 deletions base/bool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ typemax(::Type{Bool}) = true

## boolean operations ##

"""
!(x)
Boolean not.
```jldoctest
julia> !true
false
julia> !false
true
julia> ![true false true]
1×3 Array{Bool,2}:
false true false
```
"""
function !(x::Bool)
## We need a better heuristic to detect this automatically
@_pure_meta
Expand Down
Loading

0 comments on commit 0eb1f47

Please sign in to comment.