Last active
December 24, 2015 19:43
-
-
Save StevenXL/96464ba42e9feb9306d1 to your computer and use it in GitHub Desktop.
List Comprehension Over Two Lists in Elixir
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
| tax_rates = [NC: 0.075, TX: 0.08] | |
| orders = [ | |
| [id: 123, ship_to: :NC, net_amount: 100.00], | |
| [id: 124, ship_to: :OK, net_amount: 35.50], | |
| [id: 125, ship_to: :TX, net_amount: 24.00], | |
| [id: 126, ship_to: :TX, net_amount: 44.80], | |
| [id: 127, ship_to: :NC, net_amount: 25.00], | |
| [id: 128, ship_to: :MA, net_amount: 10.00], | |
| [id: 129, ship_to: :CA, net_amount: 102.00], | |
| [id: 120, ship_to: :NC, net_amount: 50.00] | |
| ] | |
| for {tax_state, tax_rate} <- tax_rates, current_order = [_, {:ship_to, order_state}, {:net_amount, amount}] <- orders do | |
| total_amount = case tax_state do | |
| order_state -> (1 + tax_rate) * amount | |
| _ -> amount | |
| end | |
| Keyword.put(current_order, :total_amount, total_amount) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment