O'Reilly logo

Clojure for Finance by Timothy Washington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Separate OR AND lookups

Our first pass at a lookup function looks fruitful. We can call it with a number of constraints and get back expected results. However, this function assumes that all our conditions are logical ORs This means a function should satisfy the a OR b OR c condition. But this will satisfy only some of our needs. Often, we'll want more than one constraint to be satisfied at the same time. This is a logical AND. Let's implement this function now. While we're at it, we can refactor our first lookup function and reuse some of its parts:

(defn generate-input-list [constraints] (if (some #{:source} constraints) (let [source-source (comp (partial filter #(= :source (first %1))) (partial partition 2)) source-value (comp second source-source) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required