Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/thoughtbot/Runes

Infix operators for monadic functions in Swift
https://github.com/thoughtbot/Runes

Last synced: about 1 month ago
JSON representation

Infix operators for monadic functions in Swift

Lists

README

        

Indecipherable symbols that some people claim have actual meaning.

[![pod](https://img.shields.io/cocoapods/v/Runes.svg)](https://cocoapods.org/)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)

Please see [the documentation] for [installation] instructions.

[the documentation]: Documentation/
[installation]: Documentation/installation.md

## What's included? ##

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

### Functor ###

- `<^>` (pronounced "map")

### Applicative Functor ###

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

### Alternative ###

- `<|>` (pronounced "alternate")
- `empty` (pronounced "empty")

### Monad ###

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

### Implementations ###

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

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

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

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

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

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

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

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

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

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

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

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

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

## Contributing ##

See the [CONTRIBUTING] document. Thank you, [contributors]!

[CONTRIBUTING]: CONTRIBUTING.md
[contributors]: https://github.com/thoughtbot/Runes/graphs/contributors

## License ##

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

[LICENSE]: /LICENSE

## About ##

![thoughtbot](https://thoughtbot.com/logo.png)

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][community] or look at
our product [case studies] and [hire us][hire] to help build your iOS app.

[community]: https://thoughtbot.com/community?utm_source=github
[case studies]: https://thoughtbot.com/ios?utm_source=github
[hire]: https://thoughtbot.com/hire-us?utm_source=github