{"id":13629525,"url":"https://github.com/Tinkoff/Visor","last_synced_at":"2025-04-17T09:34:27.131Z","repository":{"id":154867928,"uuid":"630818001","full_name":"Tinkoff/Visor","owner":"Tinkoff","description":".NET optics library","archived":true,"fork":false,"pushed_at":"2023-05-17T11:39:54.000Z","size":32,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-11-01T07:36:14.814Z","etag":null,"topics":["csharp","dotnet","fsharp","lenses","optics"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tinkoff.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null}},"created_at":"2023-04-21T08:12:39.000Z","updated_at":"2023-05-17T12:41:48.000Z","dependencies_parsed_at":"2023-09-26T03:34:56.902Z","dependency_job_id":null,"html_url":"https://github.com/Tinkoff/Visor","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"7491f077b659d7ae17286539ebce278a0e72d36a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tinkoff%2FVisor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tinkoff%2FVisor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tinkoff%2FVisor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tinkoff%2FVisor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tinkoff","download_url":"https://codeload.github.com/Tinkoff/Visor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751193,"owners_count":17196588,"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":["csharp","dotnet","fsharp","lenses","optics"],"created_at":"2024-08-01T22:01:12.825Z","updated_at":"2024-11-08T20:31:06.839Z","avatar_url":"https://github.com/Tinkoff.png","language":"C#","funding_links":[],"categories":["Do not want to test 112 ( old ISourceGenerator )"],"sub_categories":["1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category"],"readme":"# Visor\n\nTinkoff.Visor is a optics library for .NET\n\nTinkoff.Visor includes the following features:\n- C# \u0026 F# support\n- incremental lens code generator\n\n## Rationale\n\nC# introduced record types, which are a first-class implementation of immutable data types.\nWhile records are very useful for domain modeling, it can be pretty akward to modify deeply nested structures:\n\n```csharp\nrecord InnerItem(int Id, string Name);\nrecord ItemWrapper(InnerItem Item, ...);\nrecord Warehouse(ItemWrapper Main, ...);\n\nvar warehouse = new WareHouse(..); //We want to modify Id of InnerItem here\n\nvar warehouse2 = warehouse with {\n    Main = warehouse.Main with {\n        Item = warehouse.Main.Item with {\n            Id = 42 //Here is our new Id\n        }\n    }\n}\n```\n\nThis problem becomes more serious with every new level of nesting,\nand here optics come into the scene. The overall concept of optics\nis to abstract accessing (and modifying) immutable data from\nthe data itself. Let's generate `Lens` optic for the case above and see,\nhow can we re-write our modification:\n\n```csharp\n[Optics] partial record InnerItem(int Id, string Name);\n[Optics(withNested: true)] partial record ItemWrapper(InnerItem Item, ...);\n[Optics(withNested: true)] partial record Warehouse(ItemWrapper Main, ...);\n\nvar warehouse = new WareHouse(..);\n\nvar warehouse2 = Warehouse.FocusMain.FocusItem.IdLens.Set(42)(warehouse);\n```\n\n`withNested` controls \"chained\" Lens generation.\n\n`Lens` is not the only optic on the table, with `Prism` for example you can\nabstract over subtyping, with `Traverse` over enumerable structures etc.\n\n## How-to\n\n- install `Tinkoff.Visor` and `Tinkoff.Visor.Gen`\n- add `[Optics]` attribute on your record and make your record partial\n\n```csharp\n[Optics]\npartial record Sample(int Id, string Description);\n```\n\n- now you can use `Sample` static class containing optics:\n\n```csharp\nvar id = Sample.IdLens.Get(...);\n\nSample.DescriptionLens.Set(\"replaced\")(...);\n```\n\n## Coming soon\n- Prism\n- Traverse\n- Fold\n- Iso\n- utility optics for collections","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTinkoff%2FVisor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTinkoff%2FVisor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTinkoff%2FVisor/lists"}