{"id":22504944,"url":"https://github.com/bcbi/extensibleunions.jl","last_synced_at":"2025-04-14T10:10:49.703Z","repository":{"id":61797871,"uuid":"203254255","full_name":"bcbi/ExtensibleUnions.jl","owner":"bcbi","description":"Prototype of abstract multiple inheritance in Julia via extensible (mutable) type unions","archived":false,"fork":false,"pushed_at":"2020-09-06T11:11:21.000Z","size":126,"stargazers_count":9,"open_issues_count":7,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T23:23:19.865Z","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/bcbi.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}},"created_at":"2019-08-19T21:41:10.000Z","updated_at":"2025-01-02T12:46:12.000Z","dependencies_parsed_at":"2022-10-21T11:15:23.604Z","dependency_job_id":null,"html_url":"https://github.com/bcbi/ExtensibleUnions.jl","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcbi%2FExtensibleUnions.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcbi%2FExtensibleUnions.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcbi%2FExtensibleUnions.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcbi%2FExtensibleUnions.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bcbi","download_url":"https://codeload.github.com/bcbi/ExtensibleUnions.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860217,"owners_count":21173342,"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-12-07T00:12:04.262Z","updated_at":"2025-04-14T10:10:49.669Z","avatar_url":"https://github.com/bcbi.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExtensibleUnions\n\n[![Build Status](https://travis-ci.com/bcbi/ExtensibleUnions.jl.svg?branch=master)](https://travis-ci.com/bcbi/ExtensibleUnions.jl/branches)\n[![Codecov](https://codecov.io/gh/bcbi/ExtensibleUnions.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/bcbi/ExtensibleUnions.jl)\n\n```julia\njulia\u003e import Pkg; Pkg.add(\"ExtensibleUnions\")\n```\n\nExtensibleUnions adds abstract multiple inheritance to Julia in the\nform of extensible (mutable) type unions.\n\n**Warning: ExtensibleUnions is an experimental package. Do not use ExtensibleUnions in any production code.**\n\n## Usage\n\nCreate a new extensible union:\n```julia\nstruct MyUnion end\nextensibleunion!(MyUnion)\n```\n\nAdd methods that dispatch on extensible unions:\n```julia\nf(x::MyUnion1, y, z, ...) = ...\nf(x, y::MyUnion2, z, ...) = ...\nextensiblefunction!(f, MyUnion1, MyUnion2, ...)\n```\n\nAdd types to an extensible union:\n```julia\naddtounion!(MyUnion, SomeType1, SomeType2, ...)\n```\n\nAt any later time, you can add more types to an extensible union:\n```julia\naddtounion!(MyUnion, SomeType3, SomeType4, ...)\n```\n\n## Examples\n\n### Example 1\n\n```julia\njulia\u003e using ExtensibleUnions\n\njulia\u003e abstract type AbstractCar end\n\njulia\u003e abstract type AbstractFireEngine end\n\njulia\u003e struct RedCar \u003c: AbstractCar\n       end\n\njulia\u003e struct BlueCar \u003c: AbstractCar\n           x\n       end\n\njulia\u003e struct LadderTruck{T} \u003c: AbstractFireEngine\n           x::T\n       end\n\njulia\u003e mutable struct WaterTender{T} \u003c: AbstractFireEngine\n           x::T\n           y::T\n       end\n\njulia\u003e struct RedColorTrait end\n\njulia\u003e struct BlueColorTrait end\n\njulia\u003e extensibleunion!(RedColorTrait)\nRedColorTrait\n\njulia\u003e extensibleunion!(BlueColorTrait)\nBlueColorTrait\n\njulia\u003e describe(x) = \"I don't know anything about this object\"\ndescribe (generic function with 1 method)\n\njulia\u003e methods(describe)\n# 1 method for generic function \"describe\":\n[1] describe(x) in Main at REPL[12]:1\n\njulia\u003e describe(RedCar())\n\"I don't know anything about this object\"\n\njulia\u003e describe(BlueCar(1))\n\"I don't know anything about this object\"\n\njulia\u003e describe(LadderTruck{Int}(2))\n\"I don't know anything about this object\"\n\njulia\u003e describe(WaterTender{Int}(3,4))\n\"I don't know anything about this object\"\n\njulia\u003e describe(x::RedColorTrait) = \"The color of this object is red\"\ndescribe (generic function with 2 methods)\n\njulia\u003e extensiblefunction!(describe, RedColorTrait)\ndescribe (generic function with 2 methods)\n\njulia\u003e describe(x::BlueColorTrait) = \"The color of this object is blue\"\ndescribe (generic function with 3 methods)\n\njulia\u003e extensiblefunction!(describe, BlueColorTrait)\ndescribe (generic function with 3 methods)\n\njulia\u003e methods(describe)\n# 3 methods for generic function \"describe\":\n[1] describe(x::BlueColorTrait) in Main at REPL[20]:1\n[2] describe(x::RedColorTrait) in Main at REPL[18]:1\n[3] describe(x) in Main at REPL[12]:1\n\njulia\u003e describe(RedCar())\n\"I don't know anything about this object\"\n\njulia\u003e describe(BlueCar(1))\n\"I don't know anything about this object\"\n\njulia\u003e describe(LadderTruck{Int}(2))\n\"I don't know anything about this object\"\n\njulia\u003e describe(WaterTender{Int}(3,4))\n\"I don't know anything about this object\"\n\njulia\u003e addtounion!(RedColorTrait, RedCar)\nRedColorTrait\n\njulia\u003e methods(describe)\n# 3 methods for generic function \"describe\":\n[1] describe(x::BlueColorTrait) in Main at REPL[20]:1\n[2] describe(x::Union{RedCar, RedColorTrait}) in Main at REPL[18]:1\n[3] describe(x) in Main at REPL[12]:1\n\njulia\u003e describe(RedCar())\n\"The color of this object is red\"\n\njulia\u003e describe(BlueCar(1))\n\"I don't know anything about this object\"\n\njulia\u003e describe(LadderTruck{Int}(2))\n\"I don't know anything about this object\"\n\njulia\u003e describe(WaterTender{Int}(3,4))\n\"I don't know anything about this object\"\n\njulia\u003e addtounion!(BlueColorTrait, BlueCar)\nBlueColorTrait\n\njulia\u003e methods(describe)\n# 3 methods for generic function \"describe\":\n[1] describe(x::Union{RedCar, RedColorTrait}) in Main at REPL[18]:1\n[2] describe(x::Union{BlueColorTrait, BlueCar}) in Main at REPL[20]:1\n[3] describe(x) in Main at REPL[12]:1\n\njulia\u003e describe(RedCar())\n\"The color of this object is red\"\n\njulia\u003e describe(BlueCar(1))\n\"The color of this object is blue\"\n\njulia\u003e describe(LadderTruck{Int}(2))\n\"I don't know anything about this object\"\n\njulia\u003e describe(WaterTender{Int}(3,4))\n\"I don't know anything about this object\"\n\njulia\u003e addtounion!(RedColorTrait, AbstractFireEngine)\nRedColorTrait\n\njulia\u003e methods(describe)\n# 3 methods for generic function \"describe\":\n[1] describe(x::Union{BlueColorTrait, BlueCar}) in Main at REPL[20]:1\n[2] describe(x::Union{RedCar, RedColorTrait, AbstractFireEngine}) in Main at REPL[18]:1\n[3] describe(x) in Main at REPL[12]:1\n\njulia\u003e describe(RedCar())\n\"The color of this object is red\"\n\njulia\u003e describe(BlueCar(1))\n\"The color of this object is blue\"\n\njulia\u003e describe(LadderTruck{Int}(2))\n\"The color of this object is red\"\n\njulia\u003e describe(WaterTender{Int}(3,4))\n\"The color of this object is red\"\n```\n\n## Acknowledgements\n\nSome of the code in this package is taken from:\n1. [https://github.com/NHDaly/DeepcopyModules.jl](https://github.com/NHDaly/DeepcopyModules.jl) (license: MIT)\n2. [https://github.com/perrutquist/CodeTransformation.jl](https://github.com/perrutquist/CodeTransformation.jl) (license: MIT)\n\n## Related Work\n\n1. [https://github.com/rofinn/Interfaces.jl](https://github.com/rofinn/Interfaces.jl): An implementation of interfaces for Julia\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcbi%2Fextensibleunions.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbcbi%2Fextensibleunions.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcbi%2Fextensibleunions.jl/lists"}