 (defn read-from-minibuffer
   "Read a string from the minibuffer prompt. This returns an IPromise.
 
-e.g. (then (read-from-minibuffer \"Who are you? \") #(message \"Hi, %s.\" %))"
+e.g. (then (read-from-minibuffer \"Who are you? \")
+           #(message \"Hi, %s.\" %))"
   [prompt & {:keys [input history completer require-match require-coerce]
              :or {input "" history nil completer nil
                   require-match false require-coerce false}}]


;; Generic
(defn then
  "Given a RSG.IPromise<T> run (f result-value) when the promise resolves."
  [ipromise f]
  (let [ptype (type ipromise)
       of-type (.GetGenericArguments ptype)
       atype (eval `(generate-generic-type Action ~of-type))
       meth (.GetMethod ptype "Then" (into-array Type [atype]))
       arg #_(eval `(sys-action ~(apply vector of-type) [~'s] (~f ~'s)))
       (. clojure.lang.GenDelegate Create atype f)
       ]
       (.Invoke meth ipromise (into-array Object [arg]))))

(defn pcatch
  "Given an RSG.IPromise p, if p is rejected, run (f e) where e is the

   ))

(defn read-type
  "Read from the minibuffer but of a particular type. Basically Minibuffer.Read<T>().

(then (read-type Int64 \"How old are you?\")
      #(message \"%d is a fine age.\" %))
"
  [type prompt & {:keys [input history completer require-match require-coerce]
                  :or {input "" history nil completer nil
                       require-match false require-coerce false}}]
