Last active
November 19, 2019 06:59
-
-
Save ha1f/c6bb58a0725e72c678f87ba7c5cb32a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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