Swiftpack.co - Package - thoughtbot/Runes

Indecipherable symbols that some people claim have actual meaning.

pod Carthage compatible Swift Package Manager compatible

Please see the documentation for installation instructions.

What's included?

Importing Runes introduces several new operators and one global function that correspond to common Haskell typeclasses:


  • <^> (pronounced "map")

Applicative Functor

  • <*> (pronounced "apply")
  • <* (pronounced "left sequence")
  • *> (pronounced "right sequence")
  • pure (pronounced "pure")


  • <|> (pronounced "alternate")
  • empty (pronounced "empty")


  • >>- (pronounced "flatMap") (left associative)
  • -<< (pronounced "flatMap") (right associative)
  • >-> (pronounced "Monadic compose") (left associative)
  • <-< (pronounced "Monadic compose") (right associative)


We also include default implementations for Optional and Array with the following type signatures:

// Optional+Functor:
public func <^> <T, U>(f: T -> U, x: T?) -> U?

// Optional+Applicative:
public func <*> <T, U>(f: (T -> U)?, x: T?) -> U?
public func <* <T, U>(lhs: T?, rhs: U?) -> T?
public func *> <T, U>(lhs: T?, rhs: U?) -> U?
public func pure<T>(x: T) -> T?

// Optional+Alternative:
public func <|> <T>(lhs: T?, rhs: T?) -> T?
public func empty<T>() -> T?

// Optional+Monad:
public func >>- <T, U>(x: T?, f: T -> U?) -> U?
public func -<< <T, U>(f: T -> U?, x: T?) -> U?
public func >-> <T, U, V>(f: T -> U?, g: U -> V?) -> T -> V?
public func <-< <T, U, V>(f: U -> V?, g: T -> U?) -> T -> V?

// Array+Functor:
public func <^> <T, U>(f: T -> U, x: [T]) -> [U]

// Array+Applicative:
public func <*> <T, U>(fs: [T -> U], x: [T]) -> [U]
public func <* <T, U>(lhs: [T], rhs: [U]) -> [T]
public func *> <T, U>(lhs: [T], rhs: [U]) -> [U]
public func pure<T>(x: T) -> [T]

// Array+Alternative:
public func <|> <T>(lhs: [T], rhs: [T]) -> [T]
public func empty<T>() -> [T]

// Array+Monad:
public func >>- <T, U>(x: [T], f: T -> [U]) -> [U]
public func -<< <T, U>(f: T -> [U], x: [T]) -> [U]
public func >-> <T, U, V>(f: T -> [U], g: U -> [V]) -> T -> [V]
public func <-< <T, U, V>(f: U -> [V], g: T -> [U]) -> T -> [V]

// Result+Functor:
public func <^> <T, U, E>(f: (T) -> U, a: Result<T, E>) -> Result<U, E>

// Result+Applicative:
public func <*> <T, U, E>(f: Result<(T) -> U, E>, a: Result<T, E>) -> Result<U, E>
public func <* <T, U, E>(lhs: Result<T, E>, rhs: Result<U, E>) -> Result<T, E>
public func *> <T, U, E>(lhs: Result<T, E>, rhs: Result<U, E>) -> Result<U, E>
public func pure<T, E>(_ a: T) -> Result<T, E>

// Result+Alternative:
public func <|> <T, E>(lhs: Result<T, E>, rhs: @autoclosure () -> Result<T, E>) -> Result<T, E>

// Result+Monad:
public func >>- <T, U, E>(a: Result<T, E>, f: (T) -> Result<U, E>) -> Result<U, E>
public func -<< <T, U, E>(f: (T) -> Result<U, E>, a: Result<T, E>) -> Result<U, E>
public func >-> <T, U, V, E>(f: @escaping (T) -> Result<U, E>, g: @escaping (U) -> Result<V, E>) -> (T) -> Result<V, E>
public func <-< <T, U, V, E>(f: @escaping (U) -> Result<V, E>, g: @escaping (T) -> Result<U, E>) -> (T) -> Result<V, E>


See the CONTRIBUTING document. Thank you, contributors!


Runes is Copyright (c) 2015 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.



Runes is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects or look at our product case studies and hire us to help build your iOS app.


Stars: 808



5.1: five point two - 2020-05-22 01:07:20

This small release adds support for Swift 5.2 tooling, which means that if you're using Swift 5.2 you'll no longer see our test dependencies downloaded locally when you're just trying to annoy your coworkers with illegible code like a normal person.

5.0: Result - 2019-06-01 21:31:54

This release adds operator definitions for the new Result<T, E> type in Swift 5's stdlib. Accordingly, Runes 5.0 drops support for Swift versions lower than 5.0.

4.2.2: Semi-Autoclosure - 2019-05-30 13:27:59

This is a bug fix release to fix a compiler error that occured under Swift 5.0 when we tried to pass an autoclosure directly to another argument expecting an autoclosure, which is now disallowed. (Thanks @madcato!) This change should be backwards compatible with previous Swift versions.

4.2.1: Transitive Nonsense - 2019-03-19 15:08:01

This is a minor release to fix Runes as a transitive dependency when used with Swift Package Manager.

4.2: What does compatibility even mean anymore - 2019-03-15 17:25:28

This release fixes compatibility with Xcode 10.2 and Swift 5. There are no functional changes.

4.1.1: Xcode Nonsense - 2018-04-15 16:57:11

This updates the Xcode project (and some internal dependencies) so that no warnings are thrown by the Xcode project.

This will almost certainly mean nothing to you, unless you import this project into your project, in which case this will mean everything

4.1: Full Blown Applicative - 2017-06-07 19:36:34

This release fleshes out the rest of the Applicative implementations for Optional and Array. This adds two new operators to the mix for each type:

  • <* performs an applicative operation, discarding the right hand value
  • *> performs an applicative operation, discarding the left hand value

We're also adding full implementations for Alternative for both types:

  • <|> performs an alternative operation
  • empty constructs an empty value (basically the dual of pure)
  • Optional now has an .or instance method that acts as a named version of <|>.

4.0.1: Even more boring Swift Package Manager bugfix release title - 2016-11-05 01:09:48

4.0.1 fixes issues with building Runes via Swift Package Manager that were caused by a change in the way SPM expected test directories to be structured.

4.0.0: Boring Swift 3 Release Title - 2016-10-12 23:43:46

Official Swift 3.0 release!

Pretty much all @gfontenot on this one and some new operators from @inamiy

3.2.1: Legacy - 2016-07-22 19:24:43

3.2.1 adds better support for Xcode 8 and Swift 2.3 by recording these preferences in the project file. This will be the last release to support Swift 2.X, and master will move forward with Swift 3.0 support.

3.2: Mo' Monads Mo' Solutions - 2016-01-15 17:57:31

  • [NEW]: Monadic function composition! You can now use <-< and >-> to compose functions of the type T -> [U] or T -> U?. (Adam Sharp)
  • [Improved]: <^> for Arrays is now marked as @noescape (Kenneth Ackerson)

3.1.0: Legends of the Hidden Temple - 2015-10-30 22:09:52

  • [NEW]: tvOS Support (Thanks @bruceflowers!)

3.0: The Applickening - 2015-09-18 13:40:48

  • [NEW]: Swift 2.0 support
  • [NEW]: watchOS targets for Carthage and CocoaPods
  • [NEW]: Optional.apply and Array.apply are now publicly available instance methods

v3.0.0-rc.2 - 2015-07-15 17:30:52

This makes it easier to add Runes to your framework as a light weight internal dependency for introducing the operators for your own types.

- 2015-07-15 17:29:34

This adds initial support for Swift 2.0 and makes the apply instance method public for Optional and Array.

2.0.0: Precedence for President - 2015-05-04 14:22:49

This release refines the precedence for our operators to bring them in line with Haskell's implementation.

  • The map (<^>) and apply (<*>) operators now have a precedence of 130. This gives them an equal precedence with Swift's built in equality operator (==)
  • The flatMap operators (>>- and -<<) now have a precedence of 100. This gives them a precedence higher than the assignment operator (=), but lower than the or operator (||).

Note that this change flips the precedence of these operators. Previous releases gave flatMap a higher precedence than map and apply. Updating to 2.0.0 might require the addition/removal of parenthesis in your code to return to the intended behavior.

Huge thanks to @sharplet for the research (and implementation) behind this change.

1.1.2: Swift 1.1 extension capability - 2015-03-13 16:06:34

This release ensures we're compatible with the app extension APIs for Swift 1.1

1.2.2: Extension compatibility - 2015-03-13 16:04:13

This release ensures that Runes is marked as compatible with Application Extension APIs

1.2.1: Flattening the Mappening - 2015-03-13 14:38:14

This release removes the implementations of flatMap for Optionals and Arrays. flatMap is now included in the standard library for both of these types, so we don't need to duplicate their implementations here.

This release also adds a flipped operator for flatMap (-<<) and removes the guards around improper use of flatMap. These guards were needed to avoid segfaults in the compiler, but the compiler is now preventing the improper use of this operator itself.

1.2.0: Semver Synergy - 2015-02-16 19:07:43

This release is intended to be used with Swift 1.2. There are no actual changes since Runes 1.1.1, but the attached binary has been built with the Swift 1.2 compiler.

This release will not work with Swift versions 1.2 beta 3 and beyond due to the introduction of flatMap into the standard library

1.1.1: Saving us from ourselves - 2015-02-16 15:01:18

This release adds a protective ~~spell~~ compiler annotation to ensure that flatMap isn't used where map should be used. This is to prevent the Swift compiler from "helping" and coercing functions of the type A -> B to A -> B? and causing a segfault.

1.1.0: For A Few Monads More - 2015-02-16 14:52:12

This release adds default behavior for Array as well as filling out the applicative/monadic requirements by adding pure

1.0.0: A Fistful of Monads - 2015-02-16 14:49:17

Initial Release