Skip to content

Instantly share code, notes, and snippets.

@noprompt
Created March 26, 2020 18:36
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 noprompt/d94e99ba0deb980d64522dba6a61600f to your computer and use it in GitHub Desktop.
Save noprompt/d94e99ba0deb980d64522dba6a61600f to your computer and use it in GitHub Desktop.
(me/rewrite {:Sales {:Overall {:TicketCount 500
:Amount 20000}
:ByCategory [{:Name "Frontrow"
:TicketCount 200
:Amount 8000
:ByReduction [{:Name "Student"
:TicketCount 20
:Amount 100}
{:Name "Senior"
:TicketCount 100
:Amount 289}]}
{:Name "Middle"
:TicketCount 240
:Amount 8890
:ByReduction [{:Name "Student"
:TicketCount 220
:Amount 103}
{:Name "Senior"
:TicketCount 105
:Amount 289}]}]}}
{:Sales {:Overall {:TicketCount ?sales-ticket-count
:Amount ?sales-amount}
;; Use cata to process each sequence of categories !categories.
:ByCategory [(me/cata [!categories ...]) ...]}}
{:sales {:ticket-count ?sales-ticket-count
:amount ?sales-amount}
:sales-by-category [!categories ...]}
;; !categories
{:Name ?category-name
:TicketCount ?ticket-count
:Amount ?amount
:ByReduction [{:Name !reduction-name
:TicketCount !reduction-ticket-count
:Amount !reduction-amount}
...]}
[{:Name ?category-name
:TicketCount ?ticket-count
:Amount ?amount
:ticket-count ?ticket-count
:reduction-name !reduction-name
:reduction-ticket-count !reduction-ticket-count
:reduction-amount !reduction-amount}
...])
;; =>
{:sales {:ticket-count 500, :amount 20000},
:sales-by-category
[{:Name "Frontrow",
:TicketCount 200,
:Amount 8000,
:ticket-count 200,
:reduction-name "Student",
:reduction-ticket-count 20,
:reduction-amount 100}
{:Name "Frontrow",
:TicketCount 200,
:Amount 8000,
:ticket-count 200,
:reduction-name "Senior",
:reduction-ticket-count 100,
:reduction-amount 289}
{:Name "Middle",
:TicketCount 240,
:Amount 8890,
:ticket-count 240,
:reduction-name "Student",
:reduction-ticket-count 220,
:reduction-amount 103}
{:Name "Middle",
:TicketCount 240,
:Amount 8890,
:ticket-count 240,
:reduction-name "Senior",
:reduction-ticket-count 105,
:reduction-amount 289}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment