Skip to content

to4iki/Reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b2db817 · Dec 22, 2018

History

27 Commits
Dec 22, 2018
Dec 16, 2018
Dec 15, 2018
Mar 22, 2018
Dec 22, 2018
Dec 16, 2018
Mar 18, 2018
Dec 16, 2018
Mar 18, 2018
Dec 22, 2018
Dec 22, 2018
Dec 16, 2018
Dec 15, 2018

Repository files navigation

Reader

Swift 4.2 Build Status Carthage compatible

Reader monad in Swift, inspired by implemention with Scala.

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

💉

Simple and static Dependency Injection is possible with Reader

example: Playground

Installation

Add following line into your Cartfile and run carthage update.

github "to4iki/Reader"

Add following line into your Package.swift and run swift build.

dependencies: [
    .Package(url: "https://github.com/to4iki/Reader.git", majorVersion: 0)
]