                  (map (reduce comp (reverse funs))
                       vs)))))
 
-(defn whenever [entity predicate & funs]
-  (if (predicate entity)
+(defn whenever
+  "Returns `entity` modified by succesively applying `funs` if `(predicate? entity)` is true."
+  [entity predicate? & funs]
+  (if (predicate? entity)
     ((reduce comp (reverse funs))
      entity)
     entity))

(ns lambda-blog.generator
  (:refer-clojure :exclude [update])
  (:require [clojure.java.io :refer [make-parents]]
            [lambda-blog.utils :refer [pathcat]]

         html->str
         (spit-file f))))

(defn generate!
  "Transforms a part of an `entity` under `key` into an HTML page using `template` with extra `args`. Returns unmodified `entity`, but interacts with the filesystem."
  [entity key template & args]
  (do-generate! template (merge entity (entity key)) args)
  entity)

(defn generate-all!
  "Transforms a sequence of values of an `entity` under `key` into HTML pages using `template` with extra `args`. Returns `entity` unmodified, but interacts with the filesystem."
  [entity key template & args]
  (doseq [ent (entity key)]
    (do-generate! template (merge entity ent) args))
  entity)

(defn read-dir
  "Reads a directory under `path` and parses each file using `parser`. Returns `entity` with parsed file contents sequence stored under `key`."
  [entity key path parser]
  (->> path
       fs/list-dir
       (map (fn [file]
              (log/info "Reading " file)
              (parser (slurp file))))
       (assoc entity key)))
