{"id":16648501,"url":"https://github.com/w2sv/kotlin-delegates","last_synced_at":"2025-04-09T16:50:36.420Z","repository":{"id":220664103,"uuid":"752232069","full_name":"w2sv/Kotlin-Delegates","owner":"w2sv","description":"Some rather experimental kotlin delegates.","archived":false,"fork":false,"pushed_at":"2024-08-18T14:01:18.000Z","size":57,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T18:54:18.834Z","etag":null,"topics":["delegates","kotlin","kotlin-library"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/w2sv.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-03T12:29:03.000Z","updated_at":"2024-08-25T21:13:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"ccf5d2ab-05bf-4263-8492-e0d91749f56a","html_url":"https://github.com/w2sv/Kotlin-Delegates","commit_stats":null,"previous_names":["w2sv/kotlin-delegates"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2sv%2FKotlin-Delegates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2sv%2FKotlin-Delegates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2sv%2FKotlin-Delegates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2sv%2FKotlin-Delegates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w2sv","download_url":"https://codeload.github.com/w2sv/Kotlin-Delegates/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248072514,"owners_count":21043252,"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":["delegates","kotlin","kotlin-library"],"created_at":"2024-10-12T09:04:33.532Z","updated_at":"2025-04-09T16:50:36.387Z","avatar_url":"https://github.com/w2sv.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kotlin-Delegates\n\nJust some rather experimental custom kotlin delegates. Use with caution.\n\n## Usage Examples\n\n### AutoSwitch\n\n`AutoSwitch` is a delegate that automatically inverts its value upon calling its getter if the current value is equal to the specified switch condition.\n\n```kotlin\n// Create an AutoSwitch delegate with an initial value of false and switch condition true\nvar flag by AutoSwitch(value = false, switchOn = true)\n\n// Access the value, automatically inverting it if it equals the switch condition\nprintln(flag) // Output: false\nprintln(flag) // Output: true\n```\n\n### AutoSwitch.Mapped\n\n`AutoSwitch.Mapped` combines the functionality of `AutoSwitch` with that of a map delegate, allowing you to toggle boolean values stored in a mutable map.\n\n```kotlin\n// Create a mutable map to store boolean values\nval booleanMap = mutableMapOf(\"isEnabled\" to false, \"isActivated\" to true)\n\n// Create an AutoSwitch.Mapped delegate using the map and a switch condition\nval isEnabled by AutoSwitch.Mapped(booleanMap, switchOn = true)\n\n// Access the value, automatically toggling it in the map\nprintln(isEnabled) // Output: false\nprintln(isEnabled) // Output: true\n\n// The boolean value in the map has been toggled\nprintln(booleanMap[\"isEnabled\"]) // Output: true\n```\n\n### Consumable\n\n`Consumable` is a delegate for objects that should be retrieved exactly once. After getting its value, it will be automatically set to null.\n\n```kotlin\n// Create a Consumable delegate with an initial value\nval data by Consumable(\"Hello, World!\")\n\n// Access the value, consuming it and setting it to null\nprintln(data) // Output: Hello, World!\nprintln(data) // Output: null\n\n// Check if the value has been consumed\nprintln(data.isConsumable) // Output: false\n```\n\n### MapObservable\n\n`MapObservable` is a delegate that combines the functionality of a map delegate with that of an observable. It notifies a callback function when a property's value changes.\n\n```kotlin\n// Create a mutable map to store values\nval dataMap = mutableMapOf(\"counter\" to 0)\n\n// Create a MapObservable delegate with a callback function\nval counter by MapObservable(dataMap) { property, oldValue, newValue -\u003e\n    println(\"${property.name} changed from $oldValue to $newValue\")\n}\n\n// Access the value, triggering the callback function\ncounter = 42\n// Output: counter changed from 0 to 42\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw2sv%2Fkotlin-delegates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw2sv%2Fkotlin-delegates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw2sv%2Fkotlin-delegates/lists"}