{"id":21995668,"url":"https://github.com/alexdrone/primer","last_synced_at":"2025-04-30T17:27:16.256Z","repository":{"id":63902021,"uuid":"198431811","full_name":"alexdrone/Primer","owner":"alexdrone","description":"Assign/Partial/ReadOnly/Proxy/Locks in Swift","archived":false,"fork":false,"pushed_at":"2021-10-31T12:02:14.000Z","size":1605,"stargazers_count":33,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T08:44:04.953Z","etag":null,"topics":["assign","builders","combine","immutable","lock","observable","partial","passthrough","proxy","readonly","subjects","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/alexdrone.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-07-23T13:03:00.000Z","updated_at":"2024-09-12T23:14:29.000Z","dependencies_parsed_at":"2023-01-14T13:00:33.026Z","dependency_job_id":null,"html_url":"https://github.com/alexdrone/Primer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdrone%2FPrimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdrone%2FPrimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdrone%2FPrimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdrone%2FPrimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexdrone","download_url":"https://codeload.github.com/alexdrone/Primer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251750506,"owners_count":21637737,"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":["assign","builders","combine","immutable","lock","observable","partial","passthrough","proxy","readonly","subjects","swift"],"created_at":"2024-11-29T21:18:05.039Z","updated_at":"2025-04-30T17:27:16.225Z","avatar_url":"https://github.com/alexdrone.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Primer [![Swift](https://img.shields.io/badge/swift-5.1-orange.svg?style=flat)](#)\n\n### Assign\n\nThis function is used to copy the values of all enumerable own properties from one or more\nsource struct to a target struct.\nIf the argument is a reference type the same refence is returned.\n\n```swift\npublic func assign\u003cT\u003e(_ value: T, changes: (inout T) -\u003e Void) -\u003e T\n```\n\n### Partial\n\nConstructs a type with all properties of T set to optional. This utility will return a type \nthat represents all subsets of a given type.\n\nThe wrapped type can be then constructed at referred time by calling the `build()` method.\nThe instance can be later on changed with the `merge(inout _:)` method.\n\n ```swift\n struct Todo { var title: String; var description: String } \n var partial = Partial { .success(Todo(\n  title: $0.get(\\Todo.title, default: \"Untitled\"),   \n  description: $0.get(\\Todo.description, default: \"No description\"))) \n} \npartial.title = \"A Title\" \npartial.description = \"A Description\" \nvar todo = try! partial.build().get() \npartial.description = \"Another Descrition\" \ntodo = partial.merge(\u0026todo) \n```\n\n### ReadOnly\n\nConstructs a type with all properties of T set to readonly, meaning the properties of\nthe constructed type cannot be reassigned.\n\n**Note**  A read-only object can propagate change events if the wrapped type ia an\n`ObservableObject` by calling `propagateObservableObject()` at construction time.\n\n ```swift\n struct Todo { var title: String; var description: String }\n let todo = Todo(title: \"A Title\", description: \"A Description\")\n let readOnlyTodo = ReadOnly(todo)\n readOnlyTodo.title // \"A title\"\n ``` \n\n ### ObservableProxy\n \n Creates an observable Proxy for the object passed as argument (with granularity at the \n property level).\n \n\n```swift\nstruct Todo { var title: String; var description: String }\nlet todo = Todo(title: \"A Title\", description: \"A Description\")\nlet proxy = Proxy(todo)\nproxy.propertyDidChange.sink {\n  if $0.match(keyPath: \\.title) {\n    ...\n  }\n}\nproxy.title = \"New Title\"\n```\n\n### Concurrency\n\nThis package offer a variety of different lock implementations:\n* `Mutex`: enforces limits on access to a resource when there are many threads \nof execution.\n* `UnfairLock`: low-level lock that allows waiters to block efficiently on contention.\n* `ReadersWriterLock`: readers-writer lock provided by the platform implementation \nof the POSIX Threads standard.\n\nProperty wrappers to work with any of the locks above or any `NSLocking` compliant lock:\n* `@LockAtomic\u003cL: Locking\u003e`\n* `@SyncDispatchQueueAtomic`\n* `@ReadersWriterAtomic`\n\n\nThe package also includes `LockfreeAtomic`:  fine-grained atomic operations allowing for Lockfree concurrent programming. Each atomic operation is indivisible with regards to any other atomic operation that involves the same object.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdrone%2Fprimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexdrone%2Fprimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdrone%2Fprimer/lists"}