API

Modules

Types and constants

Functions and macros

Documentation

PropertyFunctions.PropertyFunctionType
struct PropertyFunction <: Function

Use only for dispatch in special cases. User code should not create instances of PropertyFunction directly - use the @fp macro instead.

The type parameters of PropertyFunction are subject to change and not part of the public API of the PropertyFunctions package.

PropertyFunctions.@pfMacro
@pf expression

Generates a function that accesses the properties of it's argument referenced via $property in expression.

@pf($a + $c^2) is equivalent to x -> x.a + x.c^2.

Examples:

xs = StructArrays.StructArray((
    a = [0.9, 0.1, 0.9, 0.2, 0.7, 0.0, 0.7, 0.5, 0.2, 0.6],
    b = [0.1, 0.5, 0.9, 0.9, 0.9, 0.6, 0.1, 0.9, 0.8, 0.2],
    c = [0.4, 0.1, 0.4, 0.1, 0.9, 0.2, 0.4, 0.8, 0.0, 0.1]
))

@pf($a + $c^2)(xs[1])
xs .|> @pf $a + $c^2

Functions generated by @pf come with broadcasting specializations that try to ensure that only the columns referenced via $colname in expr will be read, reducing memory traffic. So data.b will not be accessed in the example above. If the broadcasted function generates structs (including NamedTuples), broadcasting specialization will try to return a StructArrays.StructArray.

@pf is also very handy in sortby and filterby:

xs |> sortby(@pf $a + $c^2)
xs |> filterby(@pf $a + $c^2 < 0.5)
PropertyFunctions.filterbyFunction
filterby([getindex|view,] f)

Generates a function that filters a table-like array by f, returning either a copy (default) or a view (ignored if the object does not support views).

Example:

xs = [0.9, 0.1, 0.9, 0.2, 0.7, 0.0, 0.7, 0.5, 0.2, 0.6]
xs |> filterby(x -> x < 0.5)
PropertyFunctions.props2varsymsMethod
props2varsyms(expr)

Replace $-escaped properties in expr by generated variable names and return the original property names, new argument names and the modified expression.

Usage:

props, vars, new_expr = props2varsyms(expr)
PropertyFunctions.sortbyFunction
sortby(
    [getindex|view,]
    f;
    rev::Bool = false,
)

Generates a function that sorts and array by f, returning either a copy (default) or a view (ignored if the object does not support views).

Example:

xs = [0.9, 0.1, 0.9, 0.2, 0.7, 0.0, 0.7, 0.5, 0.2, 0.6]
xs |> sortby(x -> (x - 0.5)^2)