Skip to content

Instantly share code, notes, and snippets.

@viebel
Created December 20, 2021 12:55
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 viebel/a56c879fb73c2afce0e466c43dc6a837 to your computer and use it in GitHub Desktop.
Save viebel/a56c879fb73c2afce0e466c43dc6a837 to your computer and use it in GitHub Desktop.
Implementing associations (a la ActiveRecord) in Data-Oriented Programming
;; https://guides.rubyonrails.org/association_basics.html
(def book-info {:title "Seven Habits of Highly Effective People"})
(def author {:name "Stephen Covey"
:id "steph"})
(def association {:association-field :author-id
:parent-field :id})
(defn add-to [parent child association]
(assoc child
(:association-field association)
(get parent (:parent-field association))))
(add-to author book-info association)
;; {:title "Seven Habits of Highly Effective People"
;; :author-id "steph"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment