Skip to content

Instantly share code, notes, and snippets.

@tiensonqin
Created December 25, 2013 14:12
Show Gist options
  • Save tiensonqin/8123508 to your computer and use it in GitHub Desktop.
Save tiensonqin/8123508 to your computer and use it in GitHub Desktop.
(def v [[1 2] [1 1] [2 1] [2 4]])
(partition-by #(first %) v)
;; => (([1 2] [1 1]) ([2 1] [2 4]))
(group-by #(first %) v)
;; => {1 [[1 2] [1 1]], 2 [[2 1] [2 4]]}
;; ruby version
;; v.group_by{|v| v[0]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment