{"id":15931028,"url":"https://github.com/kimar/burrito","last_synced_at":"2025-04-03T14:21:21.888Z","repository":{"id":148488883,"uuid":"85162474","full_name":"kimar/Burrito","owner":"kimar","description":"🌯 Unwrapping your Swift optionals in a type-safe manner, backed by default values.","archived":false,"fork":false,"pushed_at":"2017-12-10T15:30:29.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T03:15:31.272Z","etag":null,"topics":["carthage","framework","ios","library","macos","optionals","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/kimar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-03-16T06:50:59.000Z","updated_at":"2017-03-31T16:01:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"4be7f42c-c6d9-4596-a54d-5b306407d8dd","html_url":"https://github.com/kimar/Burrito","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"88f8f8d81ac3392ed9efc48f79bbdaf28604bcc5"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimar%2FBurrito","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimar%2FBurrito/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimar%2FBurrito/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimar%2FBurrito/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimar","download_url":"https://codeload.github.com/kimar/Burrito/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247014513,"owners_count":20869376,"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":["carthage","framework","ios","library","macos","optionals","swift"],"created_at":"2024-10-07T01:03:25.132Z","updated_at":"2025-04-03T14:21:21.866Z","avatar_url":"https://github.com/kimar.png","language":"Swift","readme":"# 🌯 Burrito\n\n##### Type-Safe unwraps with default value.\n\nImplicitly unwrap optional values and use default values whenever needed.\n\n## Installation\n\n### Carthage\n\nAdd the following to your `Cartfile`.\n\n```swift\ngithub \"kimar/Burrito\"\n```\n\n## Quickstart\n\nBurrito helps you to get your 🌯 together and unwrap concisely and in a more readable fashion. \n\nGiven you're about to instantiate the following struct:\n\n```swift\nstruct Person {\n\tlet name: String\n}\n```\n\nWith pure Swift you're likely to see this code in you App:\n\n```swift\nlet person = Person(\n\tname: dict[\"name\"] as? String ?? \"Johnny Appleseed\"\n)\n```\n\nUsing Burrito the required type will be inferredyou can make your code as readable as this:\n\n```swift\nlet person = Person(\n\tname: dict.either(\"name\") \u003c~\u003e \"Johnny Appleseed\"\n)\n```\n\nWhat doesn't look like saving a lot of code at first clearly brings a few advantages:\n\n1. No more maintaining the type you'd like to unwrap to, the type will automatically be inferred.\n2. Easier to read code provides better maintainability\n3. A closure can be provided to compute the default value:\n\n```swift\nlet person = Person(\n\tname: dict.either(\"name\") \u003c~\u003e {\n\t\treturn computedName\n\t}\n)\n```\n\nPlease note that `\u003c~\u003e` is just syntactic sugar and can effortlessly be omitted.\n\nUnwrapping dictionaries shouldn't be painful, let *Burrito* help you unwrap:\n\n```swift\nlet json: [String: Any?] = [\n\t\"name\": Optional(\"Marcus\"),\n\t\"age\": 31,\n\t\"blog\": URL(string: \"https://blog.kida.io\")!\n]\n\nlet person = Person(\n\tname: json.unwrap(\"name\") { \"Unknown\" }, // -\u003e Marcus\n\tage: json.unwrap(\"age\") { -1 }, // -\u003e 31\n\tgithub: json.unwrap(\"github\") {\n\t\tURL(string: \"https://github.com/kimar\")!\n\t} // -\u003e https://github.com/kimar\n)\n```\n\nAs you can see, because `github` is non-existent in the payload, when trying to unwrap it a default value will be used. This value can be returned in the closure.\n\n\n## Advanced Usage\n\nBy telling *Burrito* what type you'd like to unwrap and specify a default closure returning the value you'd expect if the object can't be unwrapped or casted:\n\n**Trying to cast an `Int` to a `String` won't work e.g.:**\n\n```swift\nlet value = Burrito\u003cString\u003e.unwrap(0) {\n\treturn \"This is not the String you're looking for!\"\n}\n\nprint(value) // -\u003e \"This is not the String you're looking for!\"\n```\n\n**But when providing the correct type you'll get it's value back e.g.:**\n\n```swift\nlet myString = \"This is the String you're looking for…\"\nlet value = Burrito\u003cString\u003e.unwrap(myString) {\n\treturn \"This is not the String you're looking for!\"\n}\n\nprint(value) // -\u003e \"This is the String you're looking for…\"\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimar%2Fburrito","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimar%2Fburrito","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimar%2Fburrito/lists"}