Fork me on GitHub
#specter
<
2017-04-13
>
tankthinks13:04:41

anyone around?

tankthinks14:04:17

first and foremost … specter is awesome

tankthinks14:04:26

now that I have that out of the way

tankthinks14:04:10

I need to transform this data structure (I’ve elided unnecessary bits for now):

(def plans
  {:plans '({:planId "1"
             :disbursements ({:history ({:amount "1" :disbursementDate "2017-01-01"}
                                        {:amount "1" :disbursementDate "2017-01-01"}
                                        {:amount "2" :disbursementDate "2017-02-01"}
                                        {:amount "3" :disbursementDate "2017-03-01"})})})})

tankthinks14:04:39

by removing duplicate entries from the :history list

tankthinks14:04:52

this basically does what I want:

(transform [:plans ALL #(= "1" (:planId %)) :disbursements ALL :history]
  dedupe
  plans)

tankthinks14:04:30

but what if I want a predicate to ensure that I’m only dedupeing entries from January, i.e. “2017-01-01”

nathanmarz14:04:26

gonna have to do it manually for now in your transform fn

nathanmarz14:04:46

it's possible subselect could be extended to support that

nathanmarz14:04:28

so you could do:

(transform [:plans ALL #(= "1" (:planId %)) :disbursements ALL :history (filterer :disbursementDate #(= % “2017-01-01”))]
  dedupe
  plans)

nathanmarz14:04:52

right now subselect/`filterer` require the output sequence to be the same size as the input

nathanmarz14:04:41

the logic change would be to fill in removed entires with NONE to trigger removal

nathanmarz14:04:06

that would be a good issue to open on github

tankthinks14:04:21

Thank you for the quick response … I’ll play around a bit to make sure I completely understand, then I’ll submit an issue

nathanmarz14:04:29

actually it's fine

nathanmarz14:04:33

I was curious so I just implemented it

nathanmarz14:04:57

quite elegant I think

tankthinks14:04:13

so … uh … you’re welcome?

tankthinks14:04:21

thanks again @nathanmarz, not sure how I would have done that without specter … cheers!