Created
August 16, 2019 07:56
-
-
Save manuelsidler/8d48b687a0d27aa42116e01cf8406239 to your computer and use it in GitHub Desktop.
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
type Project = { Number : int; Cost : float } | |
let projects1 = | |
[ | |
{ Number = 1; Cost = 22.50 }; | |
{ Number = 2; Cost = 10.50 } | |
] | |
let projects2 = | |
[ | |
{ Number = 1; Cost = 80.0 }; | |
{ Number = 3; Cost = 100.0 } | |
] | |
let containsProject projectList project = | |
projectList |> List.exists (fun item -> item.Number = project.Number) | |
let updateProjects projectList project = | |
projectList | |
|> List.map (fun item -> | |
if item.Number = project.Number then { item with Cost = project.Cost + item.Cost} | |
else item) | |
let merge a b = | |
(a, b) | |
||> List.fold (fun state input -> | |
if containsProject state input then updateProjects state input | |
else input :: state) | |
merge projects1 projects2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment