Created
November 15, 2016 19:33
-
-
Save lepoetemaudit/c6eb1cfa262ec6d15abbb554b93eb4c6 to your computer and use it in GitHub Desktop.
Elm implementation of simple nested data processing
This file contains 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
import Html exposing (..) | |
worldData = | |
{ people = | |
[ { money = 129825, name = "Alice Brown" } | |
, { money = 100, name = "John Smith" } | |
, { money = 50000000000, name = "Scrooge McDuck" } | |
, { money = 2870, name = "Charlie Johnson" } | |
, { money = 8273280, name = "Michael Smith" } | |
] | |
, bank = { funds = 47000000000000000 } | |
} | |
taxIfWealthy person = | |
if person.money > 100000 then | |
({ person | money = person.money - 1000 }, 1000) | |
else | |
( person, 0 ) | |
taxPeople world = | |
let (people_, funds) = | |
List.map taxIfWealthy world.people | |
|> List.unzip | |
totalFunds = List.sum funds | |
bank = world.bank | |
bank_ = { bank | funds = world.bank.funds + totalFunds } | |
in | |
{ world | people = people_, bank = bank_ } | |
main = text <| toString <| taxPeople worldData |
Author
lepoetemaudit
commented
Nov 16, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment