目录
目录README.md

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

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)
]
关于
67.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号