Swift31/90Days – objc.io 的 Swift 片段 2

NO IMAGE
1 Star2 Stars3 Stars4 Stars5 Stars 給文章打分!
Loading...

Swift90Days – objc.io 的 Swift 片段 2

函式式快排

結合前面的 decompose

壓縮對映陣列

在函數語言程式設計裡,map

用起來也很簡單:

let ranks = ["A", "K", "Q", "J", "10",
"9", "8", "7", "6", "5", 
"4", "3", "2"]
let suits = ["♠", "♥", "♦", "♣"]
let allCards =  ranks >>= { rank in
suits >>= { suit in [(rank, suit)] }
} 
// Prints: [(A, ♠), (A, ♥), (A, ♦), 
//          (A, ♣), (K, ♠), ...


References

Functional Quicksort
Flattening and mapping arrays

相關文章

IOS開發 最新文章