Skip to content

Instantly share code, notes, and snippets.

@johnwalker
Last active January 1, 2016 12:08
Show Gist options
  • Save johnwalker/8142143 to your computer and use it in GitHub Desktop.
Save johnwalker/8142143 to your computer and use it in GitHub Desktop.
(ns play.grids)
(defprotocol Grid
(select-by-row [x r])
(select-by-col [x c])
(print [x]))
(defrecord GridSize [vvs]
Grid
(select-by-row [x r]
(nth vvs r))
(select-by-col [x c]
(map #(nth % c) vvs))
(print [x]
(doseq [x vvs] (println x))))
(-> [[1 2 3] [4 5 6] [7 8 9]]
GridSize.
(select-by-col 0))
(-> [[1 2 3] [4 5 6] [7 8 9]]
GridSize.
(select-by-row 0))
(-> [[1 2 3] [4 5 6] [7 8 9]]
GridSize.
print)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment