(ns emptyhead.thought.return
  "Utilities for handling thoughts' return values to their parents."
  (:require [emptyhead.thought.crud :as thought]
            [emptyhead.idea.protocol :as prtc]))

(defn with-return [thought namespace data]
  (if data
    (prtc/copy-fn
     #(update-in % [:return namespace] (fnil conj []) data) thought)
    thought))

(defn return-vals [thought namespace]
  (prtc/copy-fn #(get-in % [:return namespace]) thought))

(defn clear-returns [thought]
  (prtc/copy-fn #(assoc % :return {}) thought))
