{"id":18026698,"url":"https://github.com/ruiaaperes/optionalextensions","last_synced_at":"2025-09-16T18:28:33.979Z","repository":{"id":62449662,"uuid":"48812337","full_name":"RuiAAPeres/OptionalExtensions","owner":"RuiAAPeres","description":"Swift µframework with extensions for the Optional Type","archived":false,"fork":false,"pushed_at":"2019-02-18T18:48:04.000Z","size":77,"stargazers_count":181,"open_issues_count":1,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-30T21:29:46.895Z","etag":null,"topics":["functional-programming","swift","swift-extensions"],"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/RuiAAPeres.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-30T17:42:14.000Z","updated_at":"2025-07-24T14:27:27.000Z","dependencies_parsed_at":"2022-11-02T01:01:19.595Z","dependency_job_id":null,"html_url":"https://github.com/RuiAAPeres/OptionalExtensions","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/RuiAAPeres/OptionalExtensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiAAPeres%2FOptionalExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiAAPeres%2FOptionalExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiAAPeres%2FOptionalExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiAAPeres%2FOptionalExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RuiAAPeres","download_url":"https://codeload.github.com/RuiAAPeres/OptionalExtensions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiAAPeres%2FOptionalExtensions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269740355,"owners_count":24467757,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["functional-programming","swift","swift-extensions"],"created_at":"2024-10-30T08:07:44.516Z","updated_at":"2025-09-16T18:28:28.921Z","avatar_url":"https://github.com/RuiAAPeres.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OptionalExtensions\n\n\u003ca href=\"https://travis-ci.org/RuiAAPeres/OptionalExtensions\"\u003e\u003cimg src=\"https://travis-ci.org/RuiAAPeres/OptionalExtensions.svg?branch=master\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\"\u003e\u003c/a\u003e\n[![CocoaPods](https://img.shields.io/cocoapods/v/OptionalExtensions.svg)](https://cocoapods.org/)\n[![Swift 4.0](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)](https://developer.apple.com/swift/)\n[![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=flat)](https://opensource.org/licenses/MIT)\n![](https://camo.githubusercontent.com/410f44c161ebf367eacb1fcce9121e336e211bc6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506c6174666f726d2d696f732532302537432532306f737825323025374325323077617463686f7325323025374325323074766f732d6c69676874677265792e7376673f7374796c653d666c6174)\n\nWhy?\n----\n\nSwift's Optional is pretty awesome, but it can always get better. This repository is an humble attempt to add some utility methods to it.\n\nOperators\n--------\n\n* [filter](https://github.com/RuiAAPeres/OptionalExtensions#filter-wrapped---bool---optionalwrapped)\n* [mapNil](https://github.com/RuiAAPeres/OptionalExtensions#mapnil-void---wrapped---optionalwrapped)\n* [flatMapNil](https://github.com/RuiAAPeres/OptionalExtensions#flatmapnil-void---optionalwrapped---optionalwrapped)\n* [then](https://github.com/RuiAAPeres/OptionalExtensions#then-wrapped---void---void-similar-to-ts-foreach)\n* [maybe](https://github.com/RuiAAPeres/OptionalExtensions#maybe-u---wrapped---u---u-similar-to-haskells-maybe)\n* [onSome](https://github.com/RuiAAPeres/OptionalExtensions#onsome-wrapped---void---optionalwrapped-injects-a-side-effect-in-the-some-branch)\n* [onNone](https://github.com/RuiAAPeres/OptionalExtensions#onnone-void---void---optionalwrapped-injects-a-side-effect-in-the-none-branch)\n* [isSome](https://github.com/RuiAAPeres/OptionalExtensions#issome-bool)\n* [isNone](https://github.com/RuiAAPeres/OptionalExtensions#isnone-bool)\n\n#### `filter: (Wrapped -\u003e Bool) -\u003e Optional\u003cWrapped\u003e`\n\n```swift\nlet number: Int? = 3\n\nlet biggerThan2 = number.filter { $0 \u003e 2 } // .Some(3)\n\nlet biggerThan3 = number.filter { $0 \u003e 3 } // .None\n```\n\n#### `mapNil: (Void -\u003e Wrapped) -\u003e Optional\u003cWrapped\u003e`\n\n```swift\nlet number: Int? = 3\nnumber.mapNil { 2 } // .Some(3)\n\nlet nilledNumber: Int? = nil\nnilledNumber.mapNil { 2 } // .Some(2)\n```\n\n#### `flatMapNil: (Void -\u003e Optional\u003cWrapped\u003e) -\u003e Optional\u003cWrapped\u003e`\n\n```swift\nlet number: Int? = 3\nnumber.flatMapNil { .Some(2) } // .Some(3)\n\nlet nilledNumber: Int? = nil\nnilledNumber.flatMapNil { .Some(2) } // .Some(2)\n```\n\n#### `then: (Wrapped -\u003e Void) -\u003e Void` (similar to `[T]`'s `forEach`)\n\n```swift\nlet number: Int? = 3\nnumber.then { print($0) } // prints \"3\"\n\nlet nilledNumber: Int? = nil\nnilledNumber.then { print($0) } // print won't be called\n```\n\n#### `maybe: U -\u003e (Wrapped -\u003e U) -\u003e U` (similar to Haskell's `maybe`)\n\n```swift\nlet number: Int? = 3\nnumber.maybe(100) { $0 + 1 } // 4\n\nlet nilledNumber: Int? = nil\nnilledNumber.maybe(100) { $0 + 1 } // 100\n```\n\n#### `onSome: (Wrapped -\u003e Void) -\u003e Optional\u003cWrapped\u003e` (injects a side effect in the `.Some` branch)\n\n```swift\nlet number: Int? = 3\nlet sameNumber = number.onSome { print($0) } // prints \"3\" \u0026 returns .Some(3)\n\nlet nilledNumber: Int? = nil\nlet sameNilledNumber = nilledNumber.onSome { print($0) } // .None\n```\n\n#### `onNone: (Void -\u003e Void) -\u003e Optional\u003cWrapped\u003e` (injects a side effect in the `.None` branch)\n\n```swift\nlet number: Int? = 3\nlet sameNumber = number.onNone { print(\"Hello World\") } // .Some(3)\n\nlet nilledNumber: Int? = nil\nlet sameNilledNumber = nilledNumber.onNone { print(\"Hello World\") } // prints \"Hello World\" \u0026 returns .None\n```\n\n#### `isSome: Bool`\n\n```swift\nlet number: Int? = 3\nlet isSome = number.isSome // true\n\nlet nilledNumber: Int? = nil\nlet isSome = nilledNumber.isSome // false\n```\n\n#### `isNone: Bool`\n\n```swift\nlet number: Int? = 3\nlet isSome = number.isNone // false\n\nlet nilledNumber: Int? = nil\nlet isSome = nilledNumber.isNone // true\n```\n\nSetup\n-----\n\n**Carthage:**\n\n```\ngithub \"RuiAAPeres/OptionalExtensions\"\n```\n\n**CocoaPods:**\n\n```\npod \"OptionalExtensions\"\n```\n\n**Manually:**\n\nGrab the [OptionalExtensions.swift](https://github.com/RuiAAPeres/OptionalExtensions/blob/master/OptionalExtensions/Source/OptionalExtensions.swift) file and drop it in your project. \n\n\nContributing\n-----------\n\nWe will gladly accept Pull Requests with new methods or improving the ones that already exist. Documentation, or tests, are always welcome as well. ❤️\n\nLicense\n-------\n\nOptionalExtensions is licensed under the MIT License, Version 2.0. [View the license file](LICENSE)\n\nCopyright (c) 2015 Rui Peres\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruiaaperes%2Foptionalextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruiaaperes%2Foptionalextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruiaaperes%2Foptionalextensions/lists"}