Skip to content

Instantly share code, notes, and snippets.

@ha1f
Last active November 19, 2019 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ha1f/c6bb58a0725e72c678f87ba7c5cb32a7 to your computer and use it in GitHub Desktop.
Save ha1f/c6bb58a0725e72c678f87ba7c5cb32a7 to your computer and use it in GitHub Desktop.
import UIKit
protocol WoExecutable {
func を<Result>(_ process: WoProcess<Self, Result>) -> Result
}
extension WoExecutable {
func を<Result>(_ process: WoProcess<Self, Result>) -> Result {
return process.process(self)
}
}
struct WoProcess<Element, Result> {
var process: (_ e: Element) -> Result
}
extension Array: WoExecutable { }
let つなげる = WoProcess<[String], String>(process: { $0.joined() })
let 足し合わせる = WoProcess<[Int], Int>(process: { $0.reduce(0, +) })
let 数える = WoProcess<[Int], Int>(process: { $0.count })
["hoge", "hoge"].を(つなげる)
[1, 2, 3, 4, 5].を(足し合わせる)
[1, 2, 3, 4, 5].を(数える)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment