What is the best way to initialize all the elements of a JTable with Clojure?
-
06-07-2019 - |
Question
Sorry if this is a bit of a noob question but I am still getting used to functional programming.
I want to write a simple Sudoku solver as an exercise.
One of my plans is to create a JTable with 9 rows and 9 columns and initialize them all with the string "123456789" as a starting position.
If I have a TableModel I can define a function to initialize a single cell like this:
(defn initCell
"inits a cell with 123456789"
[dm row col]
(doto dm (.setValueAt "123456789" row col)))
Now what is the most Clojure like way to get this called for all cells in the 9x9 table?
Solution
Possibly like this:
(doseq [x (range 10) y (range 10)]
(initCell dm x y))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow