Giter VIP home page Giter VIP logo

accessors.jl's Introduction

Accessors

DocStable DocDev CI

The goal of Accessors.jl is to make updating immutable data simple. It is the successor of Setfield.jl.

Usage

Say you have some immutable data structure, such as a NamedTuple:

julia> nt = (a=1, b=2)
(a = 1, b = 2)

If you try something like nt.b=3, it will throw an error. But using Accessors, we can change it anyways:

julia> using Accessors

julia> @set nt.b=3
(a = 1, b = 3)

Note that this only returns an updated copy of nt, and does not overwrite or mutate the value bound to nt:

julia> nt
(a = 1, b = 2)

To overwrite the old definition, we can rebind nt to the new version:

julia> nt = @set nt.b=3
(a = 1, b = 3)

julia> nt
(a = 1, b = 3)

As this is a common use case, the convenience macro @reset rebinds the variable (nt) to the updated version:

julia> @reset nt.b=4
(a = 1, b = 4)

julia> nt
(a = 1, b = 4)

For more detail, see this tutorial and/or watch this video:

JuliaCon2020 Changing the immutable

Featured extensions

  • AccessorsExtra.jl [docs] introduces additional optics and related functions, that are considered too experimental for inclusion in Accessors. For Julia 1.8 and older, AccessorsExtra also provides integrations with other packages; for Julia 1.9+, these are mostly included in Accessors itself.

accessors.jl's People

Contributors

jw3126 avatar aplavin avatar tkf avatar github-actions[bot] avatar tpapp avatar kronosthelate avatar simeonschaub avatar balenamiaa avatar ven-k avatar christopher-dg avatar dilumaluthge avatar ranocha avatar juliatagbot avatar losses avatar rafaqz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.