JuliaCon 2025

Accessors.jl beyond @set, or a tour of the opticland
2025-07-25 , Main Room 6

The Accessors.jl package is known as a way to update values within immutable structs with its @set macro. However, the underlying "optics" concept is far more powerful and versatile. The Accessors design makes these optics impressively seamless and performant in Julia, relying heavily on multiple dispatch for composability. In the talk, I'll cover its design and implementation, showcasing neat usecases from autodiff and function optimization to tabular operations and plotting.


The Accessors package implements the concept of "optics" in Julia. In the most basic form, it addresses this common problem:
- I have a function (optic) f(x) and an object x.
- I want to get x_new similar to x but with f(x_new) = 123
That's just set(x, f, 123) in Accessors.

Thanks to both Julia powers and the clever Accessors.jl design, a very broad range of functions is supported directly. The package includes the @o macro for composing functions with familiar syntax, like @o year(first(_).dob), creating a ComposedFunction usable in set().

If you have experienced optics libraries in other languages, you will appreciate how seamlessly Accessors fits them into Julia. There is very little magic: optics are plain functions and can be called directly. They just have to be transparent and built from existing blocks: for example, a ComposedFunction instead of a black-box anonymous function.

This talk will cover the user-facing interface and internal design that enable composable and performant (typically, zero-cost) set() operations. I'll discuss both stable and experimental developments within the Julia optics ecosystem. Finally, I'll showcase various use cases where Accessors' optics shine and lead to clean and general code, including applications in autodiff, function optimization, tabular operations, plotting, and UI generation.