Exts.jl

CI status codecov.io


Usage

pkg> registry add https://github.com/0h7z/0hjl.git
pkg> add Exts
julia> using Exts

julia> Exts.ext(:) # to see which extensions are loaded
8-element Vector{Pair{Symbol, Union{Nothing, Module}}}:
             :Base => Exts.BaseExt
       :DataFrames => DataFramesExt
            :Dates => DatesExt
           :FITSIO => FITSIOExt
 :FITSIODataFrames => FITSIODataFramesExt
              :Pkg => PkgExt
       :Statistics => StatisticsExt
             :YAML => YAMLExt

API reference

Types

Exts.DatumType
Datum{T} <- Union{T, Missing}
datum(T::Type...) -> Datum{Union{T...}}
source
Exts.MaybeType
Maybe{T} <- Union{T, Nothing}
maybe(T::Type...) -> Maybe{Union{T...}}
source
Exts.LDictType
LDict <- LittleDict

An ordered dictionary type for small numbers of keys. Rather than using hash or some other sophisticated measure to store the vals in a clever arrangement, it just keeps everything in a pair of lists.

While theoretically this has expected time complexity $O(n)$ (vs the hash-based OrderedDict/Dict's expected time complexity $O(1)$, and the search-tree-based SortedDict's expected time complexity $O(\log n)$), in practice it is really fast, because it is cache & SIMD friendly.

It is reasonable to expect it to outperform an OrderedDict, with up to around 30 elements in general; or with up to around 50 elements if using a LittleDict backed by Tuples (see freeze). However, this depends on exactly how long isequal and hash take, as well as on how many hash collisions occur etc.

Note

When constructing a LittleDict it is faster to pass in the keys and values each as separate lists. So if you have them seperately already, do LittleDict(ks, vs) not LittleDict(zip(ks, vs)). Furthermore, key and value lists that are passed as Tuples will not require any copies to create the LittleDict, so LittleDict(ks::Tuple, vs::Tuple) is the fastest constructor of all.

Warning

When constructing a LittleDict, unlike hash-based OrderedDict/Dict, it does not guarantee that the keys are unique but assumes so. Use at your own risk if there might be duplicate keys.

See also LittleDicts.

source
Exts.ODictType
ODict <- OrderedDict

OrderedDicts are simply dictionaries whose entries have a particular order. The order refers to insertion order, which allows deterministic iteration over the dictionary.

See also OrderedDicts.

source
Exts.OSetType
OSet  <- OrderedSet

OrderedSets are simply sets whose entries have a particular order. The order refers to insertion order, which allows deterministic iteration over the set.

See also OrderedSets.

source
Exts.VTupleType
VTuple{T}  <- VTuple0{T}
VTuple0{T} <- Tuple{Vararg{T}}          # 0 or more
VTuple1{T} <- Tuple{T, Vararg{T}}       # 1 or more
VTuple2{T} <- Tuple{T, T, Vararg{T}}    # 2 or more
VTuple3{T} <- Tuple{T, T, T, Vararg{T}} # 3 or more
source

Macros

Exts.@S_strMacro
@S_str -> Symbol

Create a Symbol from a literal string.

Examples

julia> S"Julia"
:Julia

julia> S"$0 expands to the name of the shell or shell script."
Symbol("\$0 expands to the name of the shell or shell script.")
source
Exts.@dispMacro
@disp expr[...] -> Nothing

Evaluate an expression and display the result.

See also @show, display.

Examples

julia> @disp Maybe{AbstractVecOrMat}
Union{Nothing, AbstractVecOrMat}

julia> @disp Maybe{AbstractVecOrMat}...
Nothing
AbstractVector (alias for AbstractArray{T, 1} where T)
AbstractMatrix (alias for AbstractArray{T, 2} where T)

julia> @disp "+-×÷"...
'+': ASCII/Unicode U+002B (category Sm: Symbol, math)
'-': ASCII/Unicode U+002D (category Pd: Punctuation, dash)
'×': Unicode U+00D7 (category Sm: Symbol, math)
'÷': Unicode U+00F7 (category Sm: Symbol, math)
source
Exts.@noinfoMacro
@noinfo expr

Suppress all lexically-enclosed uses of @debug, @info.

source
Exts.@nowarnMacro
@nowarn expr

Suppress all lexically-enclosed uses of @debug, @info, @warn.

source

Functions

Exts.cisMethod
Exts.cis(x::Real) -> Complex{<:AbstractFloat}

More accurate method for exp(im*x) (especially for large x).

See also , polar, Base.cis, cispi.

Examples

julia> -1 == -Exts.cis(2π) == Exts.cis(-π) == Exts.cis(π)
true

julia> -1 != -Base.cis(2π) != Base.cis(-π) != Base.cis(π)
true
source
Exts.datumFunction
Datum{T} <- Union{T, Missing}
datum(T::Type...) -> Datum{Union{T...}}
source
Exts.extMethod
Exts.ext(::Colon) -> Vector{Pair{Symbol, Maybe{Module}}}
source
Exts.freezeMethod
freeze(d::AbstractDict{K, V}) where {K, V} -> LDict{<:K, <:V}

Render a dictionary immutable by converting it to a Tuple-backed LittleDict. The Tuple-backed LittleDict is faster than the Vector-backed LittleDict, particularly when the keys are all concretely typed.

source
Exts.invsqrtMethod
invsqrt(x::T) where T <: Real -> AbstractFloat

Return $\sqrt{x^{-1}}$.

See also sqrt.

Examples

julia> invsqrt(4)
0.5
source
Exts.isdirMethod
Exts.isdir(path::AbstractString) -> Bool

Return true if path is a directory, false otherwise.

Examples

julia> Exts.isdir(homedir())
true

julia> Exts.isdir("not/a/directory")
false

See also isfile and ispath.

source
Exts.isdirpathMethod
Exts.isdirpath(path::AbstractString) -> Bool

Determine whether a path refers to a directory (for example, ends with a path separator).

Examples

julia> Exts.isdirpath("/home")
false

julia> Exts.isdirpath("/home/")
true
source
Exts.lmapFunction
lmap(f, iterators...)

Create a lazy mapping. This is another syntax for writing (f(args...) for args in zip(iterators...)). Equivalent to Iterators.map.

See also map.

Examples

julia> collect(lmap(x -> x^2, 1:3))
3-element Vector{Int64}:
 1
 4
 9
source
Exts.maybeFunction
Maybe{T} <- Union{T, Nothing}
maybe(T::Type...) -> Maybe{Union{T...}}
source
Exts.polarMethod
polar(radius::Real, azimuth::Real) -> Complex{<:AbstractFloat}

Return $r∠θ$, where $θ$ is in degrees. Equivalent to radius∠(azimuth).

See also .

source
Exts.stdpathMethod
stdpath(path::AbstractString...; real = false) -> String

Standardize a path (or a set of paths, by joining them together), removing "." and ".." entries and changing path separator to the standard "/".

If path is a directory, the returned path will end with a "/".

If real is true, symbolic links are expanded, however the path must exist in the filesystem. On case-insensitive case-preserving filesystems, the filesystem's stored case for the path is returned.

Examples

julia> stdpath("/home/user/../example.jl")
"/home/example.jl"

julia> stdpath("Documents\\Julia\\")
"Documents/Julia/"
source
Exts.walkdirFunction
Exts.walkdir(path::AbstractString = pwd(); topdown = true) -> Channel

Return an iterator that walks the directory tree of a directory.

The iterator returns a tuple containing (path, dirs, files). Each iteration path will change to the next directory in the tree; then dirs and files will be vectors containing the directories and files in the current path directory. The directory tree can be traversed top-down or bottom-up. The returned iterator is stateful so when accessed repeatedly each access will resume where the last left off, like Iterators.Stateful.

See also readdir, Base.walkdir.

Examples

for (path, ds, fs) ∈ Exts.walkdir(".")
	@info "Directories in $path"
	for d ∈ ds
		println(path * d) # path to directories
	end
	@info "Files in $path"
	for f ∈ fs
		println(path * f) # path to files
	end
end
source
Exts.∠Method
∠(azimuth::Real) -> Complex{<:AbstractFloat}

Return $1∠θ$, where $θ$ is in degrees. Equivalent to polar(1, azimuth).

See also polar, Exts.cis.

source