<commit_before>(ns todos.todo-item)

(defn todo-create
  [n]
  (let [todo-name (atom n)
        done      (atom false)
        notes     (atom [])
        sub-todos (atom [])]
    {:name        (fn [] @todo-name)           ; fn Get name
     :rename      (partial reset! todo-name)   ; fn Rename     [string]

     :done?       (fn [] @done)                ; fn is done?
     :set-done    (partial reset! done)        ; fn set done   [true/false]

     :notes       (fn [] @notes)               ; fn Get notes
     :note-add    (partial swap! notes conj)   ; fn add a note [string]
     :note-rm     (fn [note] (swap! notes
                                    (fn [e] (vec (remove #(= % note) e)))
                                    ))

     :todos       (fn [] @sub-todos)           ; fn Get Sub-Todolist
     :todo-add    (fn [sub-todo-item]          ; fn Create a new Sub-Todo [todo-item]
                    (swap! sub-todos conj sub-todo-item))
     :todo-rm     (fn [sub-todo-item] (swap! sub-todos
                                             (fn [e] (vec (remove #(= % sub-todo-item) e)))
                                             ))

     :plain       (fn [] {:name @todo-name     ; fn transform atoms in normal data
                          :done? @done         ;    atoms cant be saved!
                          :notes @notes
                          :todos (vec (for [i @sub-todos]
                                   ((i :plain))))
                          })
     }))

; (atom []) cant be saved! be aware to build a transformfunction
;
(defn todo-load-from-plain
  [todo-plain]
  (let [item (todo-create (todo-plain :name))]
    ((item :set-done) (todo-plain :done?))
    (doseq [note (todo-plain :notes)]
      ((item :note-add) note))
    (doseq [sub-item (todo-plain :todos)]
      ((item :todo-add) (todo-load-from-plain sub-item)))
    item
    ))
<commit_msg>print of a todo-list works also with notes and subtodos<commit_after>(ns todos.todo-item)

(defn todo-create
  [n]
  (let [todo-name (atom n)
        done      (atom false)
        notes     (atom [])
        sub-todos (atom [])]
    {:name        (fn [] @todo-name)           ; fn Get name
     :rename      (partial reset! todo-name)   ; fn Rename     [string]

     :done?       (fn [] @done)                ; fn is done?
     :set-done    (partial reset! done)        ; fn set done   [true/false]

     :notes       (fn [] @notes)               ; fn Get notes
     :note-add    (partial swap! notes conj)   ; fn add a note [string]
     :note-rm     (fn [note] (swap! notes
                                    (fn [e] (vec (remove #(= % note) e)))
                                    ))

     :todos       (fn [] @sub-todos)           ; fn Get Sub-Todolist
     :todo-add    (fn [sub-todo-item]          ; fn Create a new Sub-Todo [todo-item]
                    (swap! sub-todos conj sub-todo-item))
     :todo-rm     (fn [sub-todo-item] (swap! sub-todos
                                             (fn [e] (vec (remove #(= % sub-todo-item) e)))
                                             ))

     :plain       (fn [] {:name @todo-name     ; fn transform atoms in normal data
                          :done? @done         ;    atoms cant be saved!
                          :notes @notes
                          :todos (vec (for [i @sub-todos]
                                   ((i :plain))))
                          })
     :print       (fn [pre-string]
                      (println (format "%s[ %s ] %s" pre-string (if @done "X" " ") @todo-name))
                      (doseq [note @notes] (println (format "%s    | - %s" pre-string note)))
                      (doseq [item @sub-todos] ((item :print) (str pre-string "    | ")))
                      nil
                      )
     }))

; (atom []) cant be saved! be aware to build a transformfunction
;
(defn todo-load-from-plain
  [todo-plain]
  (let [item (todo-create (todo-plain :name))]
    ((item :set-done) (todo-plain :done?))
    (doseq [note (todo-plain :notes)]
      ((item :note-add) note))
    (doseq [sub-item (todo-plain :todos)]
      ((item :todo-add) (todo-load-from-plain sub-item)))
    item
    ))

{'fraction_non_alphanumeric': 0.1399856424982053, 'fraction_numerical': 0.0, 'mean_word_length': 1.242489270386266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3914565', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1316, 'n_words': 365}