群組依據
對每個元素執行函式,並依據結果將元素分組。
群組依據操作會傳回一個雜湊映射,其金鑰為所提供函式的結果
ruby…
["bat", "it", "a", "the"].group_by{|s| s.size} # => {3=>["bat", "the"], 2=>["it"], 1=>["a"]}
clojure…
(group-by count ["bat" "it" "a" "the"]) ;; => {3 ["bat" "the"], 2 ["it"], 1 ["a"]}
由於它自然會傳回雜湊映射,因此任何下游操作都需要將此映射視為一組金鑰值對,才能繼續管線中的流程。