PropertyFunctions.jl

This package provides functionality for easy access to and efficient broadcasting over properties.

PropertyFunctions defines the macro @pf that can be used to quickly access properties of objects and broadcast efficiently over collections of objects, e.g. via xs .|> @pf $a + $c^2.

A property function can be called with a single object that has the required properties or property values can passed as keyword arguments. So @pf($a + $c^2)(a = 0.9, c = 0.4) is equivalent to @pf($a + $c^2)((a = 0.9, c = 0.4)).

Broadcasting functions generated by @pf is GPU-friendly (validated manually with CUDA.jl, GPU operation is not covered by automated CI testing) and will try to return a StructArray if the functional expression generates a struct (resp. a NamedTuple).

The package also provides convenience functions sortby and filterby that work well with functions generated by @pf (but are compatible with generic functions as well), and innermerge to merge the columns of table-like objects.

Property functions can be used with map and filter directly and get the same column-access optimizations there as in broadcasting.

Function composition f ∘ pf with a property function as the inner function results in a property function again, and compositions of pure property selections fuse into single selections. The same fusion happens in function chains built via FunctionChains.jl's ffchain/ffcomp when a property function is followed by other functions.

Input properties of property functions can be fixed to specific values via PropertyFunctions.fix_input_properties, the fixed properties then no longer count as accessed. PropertyFunctions.unfix_input_properties undoes the fixing. When PartialFunctions.jl is loaded, its $ operator can be used as well: f $ (; a = 4.2) is equivalent to PropertyFunctions.fix_input_properties(f, a = 4.2).

When Accessors.jl is loaded, optics like @o _.a.b can be converted to property functions via PropertyFunction(optic), and Accessors.set works with pure property extractions and selections.