### EQL Query with Custom Resolvers in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Illustrates defining and using custom resolvers for dynamic value computation in EQL queries. This includes resolvers for computed values based on environment and node context, as well as constant resolvers. The example shows how to pass a map of resolvers to the pour/pour function. ```clojure (require '[pour.core :as pour]) ;; Custom resolver for computed values (defn days-ago-timestamp [{:keys [now] :as env} {:keys [params]}] (let [days-ago (:days-ago params) days-ago-ms (* days-ago 24 60 60 1000)] (- now days-ago-ms))) (pour/pour {:now (inst-ms (java.util.Date.)) :resolvers {:days-ago-timestamp days-ago-timestamp}} '[(:days-ago-timestamp {:days-ago 7}) :foo] {:foo :bar}) ;; => {:days-ago-timestamp 1735987200000 :foo :bar} ;; Constant resolver example (defn constant-resolver [env node] ::constant) (pour/pour {:resolvers {:foo constant-resolver}} '[:foo (:bar {:as :hi}) {:another [:thing]} {:other [:foo1]}] {:bar 1 :another {:thing :gah} :other [{:foo1 :a :not-here :nono} {:foo1 :b :not-here :nono}]}) ;; => {:foo ::constant ;; :hi 1 ;; :another {:thing :gah} ;; :other [{:foo1 :a} {:foo1 :b}]} ``` -------------------------------- ### Advanced EQL Query with Custom Resolvers (Clojure) Source: https://github.com/clj-pour/pour/blob/master/README.md Illustrates the arity-3 version of `pour/pour` which includes an `env` argument. This `env` map can contain custom `resolvers`. The example defines a `days-ago-timestamp` resolver that calculates a timestamp based on parameters provided in the query. ```clojure (pour/pour {:now (inst-ms (java.util.Date.)) :resolvers {:days-ago-timestamp (fn [{:keys [now] :as env} {:keys [value params] :as node}] (let [days-ago (:days-ago params) days-ago-ms (* days-ago 24 60 60 1000)] (- now days-ago-ms)))}} '[(:days-ago-timestamp {:days-ago 7}) :foo] {:foo :bar}) ``` -------------------------------- ### EQL Union Queries with Custom Dispatch in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Covers querying heterogeneous collections using union queries. It shows the default union dispatch behavior based on key presence and how to define custom dispatch functions for more specific matching logic. Examples include union dispatch on data structures and routing. ```clojure (require '[pour.core :as pour]) ;; Default union dispatch matches on key presence (pour/pour [{:stuff {:record [:record :id] :type [:type :id]}}] {:stuff [{:id 1 :record :one} {:id 2 :type :two}]}) ;; => {:stuff [{:id 1 :record :one} ;; {id 2 :type :two}]} ;; Custom union dispatch function (defn custom-dispatch [union-key value] (= (:type value) union-key)) (pour/pour '[{(:stuff {:union-dispatch custom-dispatch}) {:one [:type :something] :two [:type :another]}}] {:stuff [{:type :one :id 123 :something "hi"} {:type :two :id 456 :another "thing"}]}) ;; => {:stuff [{:type :one :something "hi"} ;; {:type :two :another "thing"}]} ;; Union dispatch on routing (pour/pour '[{(:routing {:union-dispatch custom-dispatch}) {:a [:slug-a] :b [:slug-b] :c [:slug-c]}}] {:routing {:type :a :slug-a "slug-a"}}) ;; => {:routing {:slug-a "slug-a"}} ``` -------------------------------- ### EQL Pipe Resolver for Nested Queries in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Demonstrates the use of the built-in pipe resolver in EQL queries. The pipe resolver passes the current value through to nested queries, allowing for structured data manipulation. Examples show its use for aliasing nested results and combining it with other query types. ```clojure (require '[pour.core :as pour]) ;; Pipe passes value through to nested query (pour/pour '[{(:pipe {:as :aaa}) [:me]}] {:me "value"}) ;; => {:aaa {:me "value"}} ;; Combine pipe with other queries (pour/pour '[{(:pipe {:as :nested}) [:a :b]} :c] {:a 1 :b 2 :c 3}) ;; => {:nested {:a 1 :b 2} :c 3} ``` -------------------------------- ### EQL Query Parameters for Renaming and Defaults in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Explains how to use parameters within EQL queries for common tasks like renaming keys using `:as` and providing default values when a resolved value is `nil`. It also demonstrates combining various parameter uses within a single query. ```clojure (require '[pour.core :as pour]) ;; Rename keys with :as parameter (pour/pour '[(:name {:as :aliased})] {:name "person" :age 30}) ;; => {:aliased "person"} ;; Default values when resolved value is nil (pour/pour '[(:missing {:default 100}) (:boolean {:default true})] {:name "person" :boolean false}) ;; => {:boolean false :missing 100} ;; Combining parameters (pour/pour '[:foo (:bar {:as :hi}) {:another [:thing]}] {:bar 1 :another {:thing :gah}}) ;; => {:hi 1 :another {:thing :gah}} ``` -------------------------------- ### Basic EQL Query with Pour (Clojure) Source: https://github.com/clj-pour/pour/blob/master/README.md Demonstrates the basic usage of the `pour/pour` function with two arguments: an EQL query and a data value (map). It shows how to extract specific keys from the map. If a key is not found, it's omitted from the result. ```clojure (require '[pour.core :as pour]) (pour/pour [:a :b] {:a 1 :b 2 :c 3}) => {:a 1 :b 2} (pour/pour [:b] {:a 1 :c 3}) => {} ``` -------------------------------- ### Runtime Component Resolution in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Demonstrates how component dependencies can be resolved at runtime using the `renderers` environment provided to the `render` function. This allows for dynamic injection of components. ```clojure (require '[pour.compose :refer [defcup render] :as pc]) ;; Define components with unresolved dependencies (defcup us2 [:a :b] (fn [{:keys [a b]}] [:u2 a b])) (defcup us1 [{:u1 test/us2}] ;; test/us2 resolved at runtime (fn [{:keys [u1]}] [:u1 ((::pc/renderer u1) u1)])) (defcup us3 [{:u3 test/us1}] (fn [{:keys [u3]}] [:u3 ((::pc/renderer u3) u3)])) ;; Provide renderers at runtime (render {::pc/renderers {:test/us2 us2 :test/us1 us1}} us3 {:u3 {:u1 {:a 1 :b 2}}}) ;; => [:u3 [:u1 [:u2 1 2]]] ;; Single level resolution (render {::pc/renderers {:test/us2 us2}} us1 {:u1 {:a 1 :b 2}}) ;; => [:u1 [:u2 1 2]] ``` -------------------------------- ### Basic EQL Query Extraction in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Demonstrates basic property extraction and nested joins using the pour.core namespace. It shows how to select specific keys from maps and handle nested structures. Missing keys are omitted from the output. ```clojure (require '[pour.core :as pour]) ;; Simple property extraction (pour/pour [:a :b] {:a 1 :b 2 :c 3}) ;; => {:a 1 :b 2} ;; Missing keys are not included in output (pour/pour [:b] {:a 1 :c 3}) ;; => {} ;; Nested joins (pour/pour [{:another [:thing]} {:other [:foo1]}] {:another {:thing :gah} :other [{:foo1 :a :not-here :nono} {:foo1 :b :not-here :nono}]}) ;; => {:another {:thing :gah} ;; :other [{:foo1 :a} {:foo1 :b}]} ``` -------------------------------- ### Parallel Query Resolution with pour/pour in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Demonstrates asynchronous and parallel resolution of queries using `pour/pour`. Independent data paths are resolved concurrently, minimizing total resolution time. ```clojure (require '[pour.core :as pour]) (defn sleepyresolver [time v] (fn [& args] (Thread/sleep time) v)) ;; Multiple resolvers that take 25ms, 50ms, 100ms, 30ms (def env {:resolvers {:d1 (sleepyresolver 25 :d1) :d2 (sleepyresolver 50 :d2) :d3 (sleepyresolver 100 :d3) :d4 (sleepyresolver 30 :d4)}}) (def q '[{:a [:a :b]} :d1 :d2 :d3 :d4 {(:d1 {:as :foo}) [:d1 :d2 :d3 :d4]}]) ;; Total time < 250ms (not 25+50+100+30+sequential) (time (pour/pour env q {:a {:a 1}})) ;; "Elapsed time: ~150 msecs" ;; => {:a {:a 1} ;; :d1 :d1 :d2 :d2 :d3 :d3 :d4 :d4 ;; :foo {:d1 :d1 :d2 :d2 :d3 :d3 :d4 :d4}} ``` -------------------------------- ### Default Values in Components with defcup in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Illustrates how to provide default values in component queries using the `:default` option. This ensures components have fallback data when specific keys are missing in the input. ```clojure (require '[pour.compose :refer [defcup render]]) (def av "av") (defcup a1 [(:foo {:default av})] (fn [{:keys [foo]}] [:div foo])) (render a1 {}) ;; => [:div "av"] (render a1 {:foo "custom"}) ;; => [:div "custom"] ``` -------------------------------- ### Add Pour as a Git Dependency (Clojure) Source: https://github.com/clj-pour/pour/blob/master/README.md This snippet shows how to add the Pour library as a dependency in a Clojure project using the `deps.edn` file. It specifies the Git URL and a specific commit SHA for the dependency. ```clojure { :deps {pour {:git/url "https://github.com/clj-pour/pour.git" :sha "07efe0455b5473dab89af6e29bc5905a74cfd118"}}} } ``` -------------------------------- ### Define Components with defcup in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Defines components using declarative queries that specify data requirements. It supports simple components with direct data access and nested components for hierarchical composition. The `render` function executes the component with provided data. ```clojure (require '[pour.compose :refer [defcup render]]) ;; Simple component with query (defcup r4 [:a :b] (fn [{:keys [a b]}] [:div.r4 a b])) (render {} r4 {:a 1 :b 2}) ;; => [:div.r4 1 2] ;; Nested components (defcup r3 [] (fn render [{}])) (defcup r2 [{(:pipe {:as :r3}) r3} (:other {:default 1})] (fn render [{}])) (defcup r1 [:foo :bar {(:pipe {:as :r2}) r2} {(:pipe {:as :r4}) r4}] (fn render [{:keys [r4] {:keys [other]} :r2}] [:section [:span other] ((:pour.compose/renderer r4) r4)])) (render {} r1 {:a 1 :b 2}) ;; => [:section ;; [:span 1] ;; [:div.r4 1 2]] ``` -------------------------------- ### Union Components with Custom Dispatch in Clojure Source: https://context7.com/clj-pour/pour/llms.txt Composes heterogeneous collections using union queries and multiple component renderers. A `custom-dispatch` function determines how to render different types within a union, allowing for dynamic rendering based on data shape. ```clojure (require '[pour.compose :refer [defcup render] :as pc]) (defn custom-dispatch [union-key value] (= (:type value) union-key)) (defcup one-renderer [:type :something] (fn [{:keys [type something]}] [:div.one-r type something])) (defcup two-renderer [:type :another] (fn [{:keys [type another]}] [:div.two-r type another])) (defcup r5 [{(:stuff {:union-dispatch custom-dispatch}) {:one one-renderer ;; Direct reference :two test/two-render}}] ;; Runtime resolution (fn [{:as d}] [:div.r5 (for [i (:stuff d)] (let [renderer (::pc/renderer i)] (renderer i)))])) (render {::pc/renderers {:test/two-render two-renderer}} r5 {:stuff [{:type :one :id 123 :something "hi"} {:type :two :id 456 :another "thing"}]}) ;; => [:div.r5 ([:div.one-r :one "hi"] ;; [:div.two-r :two "thing"])] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.