hyperfiddle-2020 icon indicating copy to clipboard operation
hyperfiddle-2020 copied to clipboard

positional partial

Open dustingetz opened this issue 6 years ago • 1 comments

Scrap – don't know if this is possible to define semantics for.

(deftype Partial' [pfn f args]
  Fn IFn
  (-invoke [_] (pfn))
  (-invoke [_ a] (pfn a))
  (-invoke [_ a b] (pfn a b))
  ; check order of args, accounting for holes
  IEquiv IHash)

(defn -partial' [f args]
  (-> (fn [& more]

        ; Defer until we have all the args
        ; loop args
        ; if encounter a hole, apply one from more

        (apply f (concat args more)))
      (->Partial' f args)))

(partial + _ 2)
#(+ _ 2)
(fn [& args]
  ; leave as many holes as
  (+ _ 2))

(defn flip [f]
  (partial' f _2 _1))

dustingetz avatar Dec 27 '18 15:12 dustingetz

Possibly can work with nominal args (partially applying arg by name), using spec to parse ordinal args

dustingetz avatar May 16 '20 22:05 dustingetz