DataManipulation.revType
rev(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.collectviewMethod
collectview(X)

Turn the input into an AbstractArray, like collect but doesn't copy. Mostly useful for general handling of arrays and dictionaries.

DataManipulation.discreterangeMethod
discreterange(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.findonlyMethod
findonly(pred, X)

Like findfirst(pred, X), but ensures that exactly a single match is present.

DataManipulation.nestFunction
nest(::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.@sr_strMacro
sr"regex"

"Static" regular expression in the type domain. The most direct use is indexing NamedTuples and selecting columns from type-stable tables such as StructArrays. 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_strMacro
ss"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)