https://github.com/to4iki/reader
function wrapper ⚔
https://github.com/to4iki/reader
di reader reader-monad
Last synced: 4 months ago
JSON representation
function wrapper ⚔
- Host: GitHub
- URL: https://github.com/to4iki/reader
- Owner: to4iki
- License: mit
- Created: 2018-03-18T15:43:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-22T15:20:27.000Z (over 7 years ago)
- Last Synced: 2025-12-15T02:42:39.184Z (6 months ago)
- Topics: di, reader, reader-monad
- Language: Swift
- Homepage:
- Size: 35.2 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reader
[![Swift 4.2][swift-image]][swift-url]
[![Build Status][status-image]][status-url]
[![Carthage compatible][carthage-image]][carthage-url]
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`.
```swift
// init(_:)
let reader = Reader { $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 { i2 in i1 * i2 } }
.execute(4) // 24
```
## :syringe:
Simple and static **Dependency Injection** is possible with `Reader`
example: [Playground](DependencyInjection.playground/Contents.swift)
## Installation
#### [Carthage](https://github.com/Carthage/Carthage)
Add following line into your Cartfile and run `carthage update`.
```shell
github "to4iki/Reader"
```
#### [SwiftPackage Manager](https://github.com/apple/swift-package-manager)
Add following line into your Package.swift and run `swift build`.
```swift
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