   [^Future f arg-binding & body]
   `(rescue* ~f (scala/Function ~arg-binding ~@body)))
 
-(defn handle*
+(defn ^Future handle*
   [^Future f ^scala.PartialFunction pfn]
   (.handle f pfn))
 

  (:require [finagle-clojure.scala :as scala])
  (:import [com.twitter.util Await Future]))

;; call this mapcat? which is the Clojure name for flatMap?
;; or is that too confusing
(defmacro flatmap
  "Call flatMap on twitter-future.
  param-binding is a vector with 1 element, the name to bind the value of the flatMap to."
  [twitter-future param-binding & body]
  (let [tagged-future (vary-meta twitter-future assoc :tag `Future)]
    `(.flatMap ~tagged-future
        (scala/Function ~param-binding
          ~@body))))

(defmacro map
  "Call map on twitter-future.
  param-binding is a vector with 1 element, the name to bind the value of the flatMap to."
  [twitter-future param-binding & body]
  (let [tagged-future (vary-meta twitter-future assoc :tag `Future)]
    `(.map ~tagged-future
        (scala/Function ~param-binding
          ~@body))))

(defn await
  "Get the value for Future f.

          (for ~(drop 2 bindings) ~@body))
      `(do ~@body))))

(defn ^Future collect
  "Takes a seq of Futures, returns a Future of a seq of their values."
  [future-seq]
  (flatmap (Future/collect (scala/seq->scala-list future-seq))
    [scala-seq]
    (value (scala/scala-seq->List scala-seq))))

(defn ^Future rescue*
  [^Future f ^scala.PartialFunction pfn]
  (.rescue f pfn))

