Skip to content

Instantly share code, notes, and snippets.

@echeran
Last active March 13, 2021 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save echeran/f0eee2bc932a8334b2561de82ca18e16 to your computer and use it in GitHub Desktop.
Save echeran/f0eee2bc932a8334b2561de82ca18e16 to your computer and use it in GitHub Desktop.
Reusing your fns as Clojure serialized fns to use in Flambo (Spark wrapper for Clojure)
(require '[clj-time.core :as t])
(require '[flambo.api :as f])
(defn date-filter-fn
"Given a LocalDate, returns a serializable fn that takes a DateTime
object and returns true if the DateTime fields match those of the
provided LocalDate, else returns false."
[local-date]
;; returning a serializable fn to be used with Flambo/Spark's filter operation
(f/fn
[date-time]
(boolean
(and
(= (t/day local-date) (t/day date-time)))
(= (t/month local-date) (t/month date-time))
(= (t/year local-date) (t/year date-time))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment