DataManipulation.rev
— Typerev(val)
A wrapper that reverses the order of isless
comparisons. Useful when sorting by several keys, some forward, some reverse.
Examples
sort(..., by=x -> (x.a, rev(x.b), rev(x.c)))
DataManipulation.collectview
— Methodcollectview(X)
Turn the input into an AbstractArray
, like collect
but doesn't copy. Mostly useful for general handling of arrays and dictionaries.
DataManipulation.discreterange
— Methoddiscreterange(f, start, stop; length)
Similar to maprange(...)
, but return length
unique integers.
Example
10 log-spaced values from 1 to 100:
# regular floating-point maprange
julia> maprange(log, 1, 100, length=10)
10-element FlexiMaps.MappedArray{Float64, 1, FlexiMaps.var"#12#13"{typeof(log), Int64, Int64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Int64, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}:
1.0
1.6681005372000588
2.7825594022071245
4.641588833612779
7.742636826811271
12.915496650148844
21.544346900318843
35.93813663804628
59.948425031894104
100.0
# discreterange of integers
julia> discreterange(log, 1, 100, length=10)
10-element Vector{Int64}:
1
2
3
5
9
14
23
38
61
100
DataManipulation.filterfirst
— Methodfilterfirst(pred, X)
More efficient first(filter(pred, X))
.
DataManipulation.filteronly
— Methodfilteronly(pred, X)
More efficient only(filter(pred, X))
.
DataManipulation.findonly
— Methodfindonly(pred, X)
Like findfirst(pred, X)
, but ensures that exactly a single match is present.
DataManipulation.materialize_views
— Method" materialize_views(X)
Materialize views arbitrarily nested in dictionaries and StructArray
s.
DataManipulation.nest
— Functionnest(::NamedTuple, [sr"regex" [=> (ss"sub", ...)], ...])
nest(::StructArray, [sr"regex" [=> (ss"sub", ...)], ...])
Put a subset of properties into a nested object of the same kind (eg a nested NamedTuple
`).
Properties to nest are selected in compile time by a regular expression. Their resulting names are extracted from the regex groups, or specified explicitly by substitution strings.
Examples
julia> nest((a_x=1, a_y="2", a_z_z=3, b=:z), sr"(a)_(\w+)" ))
(a=(x=1, y="2", z_z=3), b=:z)
julia> nest( (a_x=1, a_y="2", a_z_z=3, b=:z), sr"(a)_(\w+)" => (ss"x\1", ss"val", ss"\2") ))
(xa=(val=(x=1, y="2", z_z=3),), b=:z)
DataManipulation.shift_range
— Functionshift_range(x, a..b => A..B; clamp=false)
Linearly transform x
from range a..b
to A..B
.
DataManipulation.sortview
— Methodsortview(X; kws...)
Like sort(X; kws...)
, but returns a view instead of a copy.
DataManipulation.uniqueonly
— Functionuniqueonly([pred], X)
More efficient only(unique([pred], X))
.
DataManipulation.uniqueview
— Methoduniqueview([f], X)
Like unique([f], X)
, but returns a view instead of a copy.
DataManipulation.@sr_str
— Macrosr"regex"
"Static" regular expression in the type domain. The most direct use is indexing NamedTuple
s and selecting columns from type-stable tables such as StructArray
s. The underlying value can be extracted with the unstatic()
function.
See also: ss"substitution"
, nest
.
Examples
nt = (a_1=1, a_2=10, b_1=100)
# select a subset of nt by regex:
nt[sr"a_\d"] === (a_1 = 1, a_2 = 10)
# select and rename by regex and substitution string:
nt[sr"a_(\d)" => ss"xxx_\1_xxx"] === (xxx_1_xxx = 1, xxx_2_xxx = 10)
DataManipulation.@ss_str
— Macross"substitution"
"Static" substitution string in the type domain. The underlying value can be extracted with the unstatic()
function.
See also: sr"regex"
, nest
.
Examples
nt = (a_1=1, a_2=10, b_1=100)
# select and rename by regex and substitution string:
nt[sr"a_(\d)" => ss"xxx_\1_xxx"] === (xxx_1_xxx = 1, xxx_2_xxx = 10)