Swift is still very new, but all kinds of interesting libraries are being created around it. Dollar is a great example, providing useful functional programming language helpers. There are 2 parts to the library — Dollar is purely functional and Cent includes extension to built-in classes. The GitHub repository has many examples, but here's a few highlights:
$.difference([1, 2, 3, 4, 5], [5, 2, 10])
> [1, 3, 4]
$.flatten([[[3], 4], 5]) as Int[]
> [3, 4, 5]
let arr = [["age": 20], ["age": 30], ["age": 40]]
$.pluck(arr, value: "age")
> [20, 30, 40]
let fibMemo = $.memoize { (fib: (Int -> Int), val: Int) -> Int in
return val == 1 || val == 0 ? 1 : fib(val - 1) + fib(val - 2)
}
let x = fibMemo(5)
var beatle = Car(name: "Fusca")
$.tap(beatle, {$0.name = "Beatle"}).color = "Blue"
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.
.