to4iki/reader
Reader monad in Swift, inspired by [implemention with Scala](https://gist.github.com/Mortimerp9/5384467).
Overview
Reader is a wrapper for function that take some Input and produce Element.
// init(_:)
let reader = Reader<Int, Int> { $0 + 2 }
// execute(_:)
reader.execute(1) // 3
reader.execute(2) // 4
// map(_:)
reader
.map { $0 * 2 }
.execute(3) // 10
// flatMap(_:)
reader
.flatMap { i1 in Reader<Int, Int> { i2 in i1 * i2 } }
.execute(4) // 24:syringe:
Simple and static Dependency Injection is possible with Reader
example: Playground
Installation
Carthage
Add following line into your Cartfile and run carthage update.
github "to4iki/Reader"SwiftPackage Manager
Add following line into your Package.swift and run swift build.
dependencies: [
.Package(url: "https://github.com/to4iki/Reader.git", majorVersion: 0)
][swift-url]: https://swift.org/download/ [swift-image]: https://img.shields.io/badge/swift-4.2-orange.svg?style=flat
[status-url]: https://travis-ci.org/to4iki/Reader [status-image]: https://travis-ci.org/to4iki/Reader.svg
[carthage-url]: https://github.com/Carthage/Carthage [carthage-image]: https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat
Package Metadata
Repository: to4iki/reader
Default branch: master
README: README.md