{"id":15360534,"url":"https://github.com/devmotion/simpleunpack.jl","last_synced_at":"2025-04-14T06:36:48.994Z","repository":{"id":114024582,"uuid":"609578862","full_name":"devmotion/SimpleUnPack.jl","owner":"devmotion","description":"Lightweight Julia macro for destructuring properties and fields","archived":false,"fork":false,"pushed_at":"2024-12-01T12:35:17.000Z","size":31,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T12:23:04.870Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devmotion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-04T15:53:00.000Z","updated_at":"2024-12-01T12:35:15.000Z","dependencies_parsed_at":"2024-08-14T15:34:36.023Z","dependency_job_id":null,"html_url":"https://github.com/devmotion/SimpleUnPack.jl","commit_stats":{"total_commits":14,"total_committers":4,"mean_commits":3.5,"dds":0.5714285714285714,"last_synced_commit":"cea0bbee056bbe13d686a4d466f93cf8d0f86151"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2FSimpleUnPack.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2FSimpleUnPack.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2FSimpleUnPack.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmotion%2FSimpleUnPack.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devmotion","download_url":"https://codeload.github.com/devmotion/SimpleUnPack.jl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245916741,"owners_count":20693400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T12:50:30.537Z","updated_at":"2025-03-27T20:19:57.454Z","avatar_url":"https://github.com/devmotion.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleUnPack\n\n[![Build Status](https://github.com/devmotion/SimpleUnPack.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/devmotion/SimpleUnPack.jl/actions/workflows/CI.yml?query=branch%3Amain)\n[![Coverage](https://codecov.io/gh/devmotion/SimpleUnPack.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/devmotion/SimpleUnPack.jl)\n[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)\n\nThis package provides four macros, namely\n\n- `@unpack` for destructuring properties,\n- `@pack!` for setting properties,\n- `@unpack_fields` for destructuring fields,\n- `@pack_fields!` for setting fields.\n\n`@unpack`/`@pack!` are based on `getproperty`/`setproperty` whereas `@unpack_fields`/`@pack_fields!` are based on `getfield`/`setfield!`.\n\nIn Julia \u003e= 1.7.0-DEV.364, `@unpack` is expanded to the destructuring syntax that was introduced in [Julia#39285](https://github.com/JuliaLang/julia/pull/39285).\n\n## Examples\n\nAn example with `NamedTuple` in global scope:\n\n```julia\njulia\u003e using SimpleUnPack\n\njulia\u003e f(x) = (; b=x, a=x/2);\n\njulia\u003e @unpack a, b = f(42)\n(b = 42, a = 21.0)\n\njulia\u003e a\n21.0\n\njulia\u003e b\n42\n\njulia\u003e @unpack_fields a, b = f(10)\n(b = 10, a = 5.0)\n\njulia\u003e a\n5.0\n\njulia\u003e b\n10\n```\n\nAn example with a custom struct in a function:\n\n```julia\njulia\u003e using SimpleUnPack\n\njulia\u003e mutable struct MyStruct{X,Y}\n           x::X\n           y::Y\n       end\n\njulia\u003e Base.propertynames(::MyStruct) = (:x, :y)\n\njulia\u003e function Base.getproperty(m::MyStruct, p::Symbol)\n           if p === :y\n               return 42\n           else\n               return getfield(m, p)\n           end\n       end\n\njulia\u003e function Base.setproperty!(m::MyStruct, p::Symbol, v)\n           if p === :y\n               setfield!(m, p, 2 * v)\n           else\n               setfield!(m, p, v)\n           end\n       end\n\njulia\u003e function g(m::MyStruct)\n           @unpack x, y = m\n           return (; x, y)\n       end;\n\njulia\u003e g(MyStruct(1.0, -5))\n(x = 1.0, y = 42)\n\njulia\u003e function g!(m::MyStruct, x, y)\n          @pack! m = x, y\n          return m\n       end;\n\njulia\u003e g!(MyStruct(2.1, 5), 1.2, 2)\nMyStruct{Float64, Int64}(1.2, 4)\n\njulia\u003e function h(m::MyStruct)\n           @unpack_fields x, y = m\n           return (; x, y)\n       end\n\njulia\u003e h(MyStruct(1.0, -5))\n(x = 1.0, y = -5)\n\njulia\u003e function h!(m::MyStruct, x, y)\n          @pack_fields! m = x, y\n          return m\n       end;\n\njulia\u003e h!(MyStruct(2.1, 5), 1.2, 2)\nMyStruct{Float64, Int64}(1.2, 2)\n```\n\n## Comparison with UnPack.jl\n\nThe syntax of `@unpack` and `@pack!` is based on `UnPack.@unpack` and `UnPack.@pack!` in [UnPack.jl](https://github.com/mauro3/UnPack.jl).\n\n`UnPack.@unpack`/`UnPack.@pack!` are more flexible since they are based on `UnPack.unpack`/`UnPack.pack!` instad of `getproperty`/`setproperty!`.\nWhile `UnPack.unpack`/`UnPack.pack!` fall back to `getproperty`/`setproperty!`, they also support `AbstractDict`s with keys of type `Symbol` and `AbstractString` and can be specialized for other types.\nSince `UnPack.unpack` and `UnPack.pack!` dispatch on `Val(property)` instances, this increased flexibility comes at the cost of increased number of specializations and increased compilation times.\n\nIn contrast to SimpleUnPack, currently UnPack does not support destructuring/updating based on `getfield`/`setfield!` only ([UnPack#23](https://github.com/mauro3/UnPack.jl/issues/23)).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevmotion%2Fsimpleunpack.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevmotion%2Fsimpleunpack.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevmotion%2Fsimpleunpack.jl/lists"}