Skip to content

More functional API #6

@currentoor

Description

@currentoor

Right now we have a single global -pluck multimethod. This works for now but it's rigid. We can't override a particular key in certain contexts without mutating the behavior everywhere.

Higher order functions would allow more flexibility. Something like

(defmulti pluck-handler
  (fn [k env init-result] k))

(defmethod pluck-handler :default [k env init-result]
  (get init-result k))

(defmethod pluck-handler :data-source/fields [k {db :db} {:keys [data-source/fields-str]}]
  (clojure.edn/read-string fields-str))

(def pluck (adstage.pluck-api/buildpluck-handler-fn
            ;; The subroutine that handles wrapping the pull results.
            :pluck-handler pluck-handler
            ;; Keys the pluck API should wrap.
            :pluckable? (fn [key] (contains? (methods pluck-handler) key))
            ;; Map of pluck API keys to Datomic keys.
            :prepluck-handler  {:data-source/fields :data-source/fields-str}))

(pluck {:db db} [:db/id :data-source/fields] 17592186057566)

;; =>
{:db/id              17592186057566
 :data-source/fields ["spend" "clicks" "ctr"]}

So instead of providing pluck, we provide a pluck factory.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions