I’m basing the structure of this repo (*.edn
files, etc) off of tschady’s repo.
My Clojure solutions to the Advent of Code challenge (to be reused over multiple years).
Handy scripts (thanks tschady) are in script
.
bb.edn
defines tasks that call them.
e.g. To create stub files for 2023 day 7, download the data to resources/day07.txt
and open the websites for the problem and data, run:
bb go -y 2023 -d 7
Use deps.edn
to define dependencies and paths.
Files in src
and resources
can be found during runtime.
Tests use file in test
.
Tests are under tests
.
Tests use kaocha
(not sure how this works yet).
kaocha
recommends setting up test configs in tests.edn
.
Run with
bb test
https://clojure.org/reference/transducers
The kind of function you’d pass to reduce
Takes an accumulated result and a new input and returns a new accumulated result.
A transformation from one reducing function to another.
Examples
(filter odd?) ;; returns a transducer that filters odd
(map inc) ;; returns a mapping transducer for incrementing
(take 5) ;; returns a transducer that will take the first 5 values
Use the existing comp
function.
comp
applies the rightmost function to the parameters, then the next rightmost function to the result, and so on.
(def xf
(comp
(filter odd?)
(map inc)
(take 5)))
The transformation above is equivalent to the sequence transformation
(->> coll
(filter odd?)
(map inc)
(take 5))