RuiAAPeres / Optionalextensions
Licence: mit
Swift µframework with extensions for the Optional Type
Stars: ✭ 181
Programming Languages
swift
15916 projects
Labels
Projects that are alternatives of or similar to Optionalextensions
Mostly Adequate Guide Chinese
函数式编程指北中文版
Stars: ✭ 2,093 (+1056.35%)
Mutual labels: functional-programming
Wiwinwlh
What I Wish I Knew When Learning Haskell
Stars: ✭ 2,250 (+1143.09%)
Mutual labels: functional-programming
Nmf App
Understand and reduce your carbon footprint 🌱 iOS & Android.
Stars: ✭ 176 (-2.76%)
Mutual labels: functional-programming
Scala Server Toolkit
Functional programming toolkit for building server applications in Scala.
Stars: ✭ 170 (-6.08%)
Mutual labels: functional-programming
Scala Workflow
Boilerplate-free syntax for computations with effects
Stars: ✭ 173 (-4.42%)
Mutual labels: functional-programming
Stegcloak
Hide secrets with invisible characters in plain text securely using passwords 🧙🏻♂️⭐
Stars: ✭ 2,379 (+1214.36%)
Mutual labels: functional-programming
Bow Arch
🏛 Functional Architecture in Swift using Bow
Stars: ✭ 166 (-8.29%)
Mutual labels: functional-programming
Potigol
Linguagem Potigol - Linguagem de programação funcional moderna para iniciantes - A Functional Programming Language for Beginners
Stars: ✭ 179 (-1.1%)
Mutual labels: functional-programming
Iota
Fast [co]product types with a clean syntax. For Cats & Scalaz.
Stars: ✭ 175 (-3.31%)
Mutual labels: functional-programming
Cuneiform
Cuneiform distributed programming language
Stars: ✭ 175 (-3.31%)
Mutual labels: functional-programming
Hm Def
Runtime type checking for JS with Hindley Milner signatures
Stars: ✭ 171 (-5.52%)
Mutual labels: functional-programming
Curryable
An elegant and simple curry(f) implementation in PHP.
Stars: ✭ 172 (-4.97%)
Mutual labels: functional-programming
Ocaml Jupyter
An OCaml kernel for Jupyter (IPython) notebook
Stars: ✭ 177 (-2.21%)
Mutual labels: functional-programming
Libf
C++ as a Pure Functional Programming Language
Stars: ✭ 167 (-7.73%)
Mutual labels: functional-programming
Functional Examples
Examples with Functional JavaScript, following Professor Frisby's course
Stars: ✭ 179 (-1.1%)
Mutual labels: functional-programming
Deal
Design by contract for Python with static checker and tests' generation.
Stars: ✭ 164 (-9.39%)
Mutual labels: functional-programming
Akar
First-class patterns for Clojure. Made with love, functions, and just the right amount of syntax.
Stars: ✭ 176 (-2.76%)
Mutual labels: functional-programming
Fika
A statically typed functional programming language for the web.
Stars: ✭ 179 (-1.1%)
Mutual labels: functional-programming
Immutable
Thread-safe, persistent, immutable collections for the Crystal language
Stars: ✭ 179 (-1.1%)
Mutual labels: functional-programming
Maryamyriameliamurphies.js
A library of Haskell-style morphisms ported to ES2015 JavaScript using Babel.
Stars: ✭ 177 (-2.21%)
Mutual labels: functional-programming
OptionalExtensions
Why?
Swift's Optional is pretty awesome, but it can always get better. This repository is an humble attempt to add some utility methods to it.
Operators
filter: (Wrapped -> Bool) -> Optional<Wrapped>
let number: Int? = 3
let biggerThan2 = number.filter { $0 > 2 } // .Some(3)
let biggerThan3 = number.filter { $0 > 3 } // .None
mapNil: (Void -> Wrapped) -> Optional<Wrapped>
let number: Int? = 3
number.mapNil { 2 } // .Some(3)
let nilledNumber: Int? = nil
nilledNumber.mapNil { 2 } // .Some(2)
flatMapNil: (Void -> Optional<Wrapped>) -> Optional<Wrapped>
let number: Int? = 3
number.flatMapNil { .Some(2) } // .Some(3)
let nilledNumber: Int? = nil
nilledNumber.flatMapNil { .Some(2) } // .Some(2)
then: (Wrapped -> Void) -> Void
(similar to [T]
's forEach
)
let number: Int? = 3
number.then { print($0) } // prints "3"
let nilledNumber: Int? = nil
nilledNumber.then { print($0) } // print won't be called
maybe: U -> (Wrapped -> U) -> U
(similar to Haskell's maybe
)
let number: Int? = 3
number.maybe(100) { $0 + 1 } // 4
let nilledNumber: Int? = nil
nilledNumber.maybe(100) { $0 + 1 } // 100
onSome: (Wrapped -> Void) -> Optional<Wrapped>
(injects a side effect in the .Some
branch)
let number: Int? = 3
let sameNumber = number.onSome { print($0) } // prints "3" & returns .Some(3)
let nilledNumber: Int? = nil
let sameNilledNumber = nilledNumber.onSome { print($0) } // .None
onNone: (Void -> Void) -> Optional<Wrapped>
(injects a side effect in the .None
branch)
let number: Int? = 3
let sameNumber = number.onNone { print("Hello World") } // .Some(3)
let nilledNumber: Int? = nil
let sameNilledNumber = nilledNumber.onNone { print("Hello World") } // prints "Hello World" & returns .None
isSome: Bool
let number: Int? = 3
let isSome = number.isSome // true
let nilledNumber: Int? = nil
let isSome = nilledNumber.isSome // false
isNone: Bool
let number: Int? = 3
let isSome = number.isNone // false
let nilledNumber: Int? = nil
let isSome = nilledNumber.isNone // true
Setup
Carthage:
github "RuiAAPeres/OptionalExtensions"
CocoaPods:
pod "OptionalExtensions"
Manually:
Grab the OptionalExtensions.swift file and drop it in your project.
Contributing
We will gladly accept Pull Requests with new methods or improving the ones that already exist. Documentation, or tests, are always welcome as well. ❤️
License
OptionalExtensions is licensed under the MIT License, Version 2.0. View the license file
Copyright (c) 2015 Rui Peres
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].