In Clojure, ->
is used for inserting the piped argument at the head position in the arguments of whatever it is passed to, while ->>
is used for inserting it at the tail. This approach is great for working with immutable data in a series of approachable transformations, which I believe is one reason why so many Domain-Specific Languages for generative programming are written in that language, aside from its interactive REPL. Additionally, there is no need to worry about excessive copying, as this is generally well optimized.
This can be particularly useful with HoneySQL, which is more of a DSL for SQL rather than a typical ORM tool. For example:
(defn apply-filters [query filters]
"applies WHERE clauses to a query"
(reduce (fn [q [column value]]
(helpers/where q [:= column value]))
query
filters))
(defn build-dynamic-query [{:keys [table columns filters sort-by limit]}]
(-> {}
(helpers/select columns)
(helpers/from table)
(apply-filters filters)
(helpers/order-by sort-by)
(helpers/limit limit)
sql/format))
;; Result - a super readable function call that resembles a natural language
(build-dynamic-query
{:table :products
:columns [:id :name :price]
:filters {:category "electronics" :in-stock true}
:sort-by [:price :desc]
:limit 20})
wake me up when Rust fixes its’ supply chain attacks susceptibility (solid stdlib and rejecting external crates, including transitive deps