{"id":18002837,"url":"https://github.com/am-kantox/pyc","last_synced_at":"2025-03-26T08:31:20.020Z","repository":{"id":57538146,"uuid":"169777869","full_name":"am-kantox/pyc","owner":"am-kantox","description":"Set of additional functionality for structs","archived":false,"fork":false,"pushed_at":"2019-02-13T07:32:32.000Z","size":37,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-21T12:21:59.968Z","etag":null,"topics":["elixir","elixir-lang","structs"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/am-kantox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-08T18:09:31.000Z","updated_at":"2022-10-29T18:44:14.000Z","dependencies_parsed_at":"2022-09-07T16:50:34.871Z","dependency_job_id":null,"html_url":"https://github.com/am-kantox/pyc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/am-kantox%2Fpyc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/am-kantox%2Fpyc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/am-kantox%2Fpyc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/am-kantox%2Fpyc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/am-kantox","download_url":"https://codeload.github.com/am-kantox/pyc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245618752,"owners_count":20645061,"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":["elixir","elixir-lang","structs"],"created_at":"2024-10-29T23:24:11.498Z","updated_at":"2025-03-26T08:31:18.786Z","avatar_url":"https://github.com/am-kantox.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pyc\n\n[![CircleCI](https://circleci.com/gh/am-kantox/pyc.svg?style=svg)](https://circleci.com/gh/am-kantox/pyc)  **Struct on steroids: insertion validation, handy pipelining and more.**\n\n## Usage\n\nDeclare the struct with `use Pyc, definition: ...` and get helper macros\nto deal with the struct alongside the validation of updates for free.\n\nValidation of updates works for all injected `MyStruct.put/3` functions that\nbasically substitute the generic `Map.put/3` as well as for `Collectable.into/1`\nautomatically implemented for the struct defined that way.\n\nAll functions declared with `defmethod/3` get `this` local variable as well as\nthe bunch of local variables for all the keys of the struct.\n\nEasy monadic chaining is possible with generic pipe operator.\n\n```elixir\ndefmodule MyStruct do\n  use Pyc,\n    definition: [foo: 42, bar: %{}, baz: []],\n    constraints: [%{matches: %{foo: 42, bar: ~Q[bar]}, guards: %{check_bar: \"is_map(bar)\"}}]\n\n  defmethod :foo!, [value] when foo \u003c 100 and length(baz) \u003e 0 do\n    %__MODULE__{this | foo: value, baz: [42 | baz]}\n  end\nend\n\n\niex\u003e %MyStruct{}\n...\u003e |\u003e MyStruct.put(:baz, 42)\n...\u003e |\u003e IO.inspect(label: \"1st put\")\n...\u003e |\u003e MyStruct.put(:baz, [])\n...\u003e |\u003e IO.inspect(label: \"2nd put\")\n...\u003e |\u003e MyStruct.put(:bar, 42)\n...\u003e |\u003e IO.inspect(label: \"3rd put\")\n#⇒ 1st put: %MyStruct{bar: %{}, baz: 42, foo: 42}\n#  2nd put: %MyStruct{bar: %{}, baz: [], foo: 42}\n#  3rd put: {:error, %MyStruct{bar: 42, baz: [], foo: 42}}\n\niex\u003e Enum.into([bar: %{zzz: nil}, baz: \"¡Hola!\"], %MyStruct)\n#⇒ %MyStruct{bar: %{zzz: nil}, baz: \"¡Hola!\", foo: 42}\n\niex\u003e Enum.into([bar: 42], %MyStruct)\n#⇒ {:error, %MyStruct{bar: 42, baz: [], foo: 42}}\n```\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:pyc, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Docs\n\n→ [https://hexdocs.pm/pyc](https://hexdocs.pm/pyc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fam-kantox%2Fpyc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fam-kantox%2Fpyc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fam-kantox%2Fpyc/lists"}