Created
March 16, 2017 19:35
-
-
Save dupuchba/b137ee3339eb8277e372b9cc30ae20dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn move-element [state from to element] | |
(letfn [(remove* [elements ref] | |
(into [] (remove #{ref} elements))) | |
(add* [elements ref] | |
(into [] (cond-> elements | |
(not (some #{ref} elements)) (conj ref))))] | |
(-> state | |
(update-in (conj from :elements) remove* element) | |
(update-in (conj to :elements) add* element)))) | |
(defmethod mutate 'element/drop | |
[{:keys [state]} _ {:keys [from to element]}] | |
{:value {:keys [element from to]} | |
:action (fn [] | |
(swap! state move-element from to element))}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment