Created
November 4, 2018 20:27
-
-
Save ufocoder/45d16524932a5256b55c1ae0dcf583eb to your computer and use it in GitHub Desktop.
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
| type alias Book = | |
| { isbn : String | |
| , title : String | |
| , authors : List String | |
| , copyright : Int | |
| , edition : Maybe String | |
| } | |
| type alias LibraryReport = | |
| { numBooks : Int | |
| , oldestCopyright : Int | |
| , newestCopyright : Int | |
| , uniqueAuthors : Int | |
| } | |
| createReport : List Book -> LibraryReport | |
| createReport books = | |
| let | |
| copyrightYears = | |
| List.map .copyright books | |
| in | |
| { numBooks = List.length books | |
| , oldestCopyright = | |
| List.minimum copyrightYears | |
| |> Maybe.withDefault 0 | |
| , newestCopyright = | |
| List.maximum copyrightYears | |
| |> Maybe.withDefault 0 | |
| , uniqueAuthors = | |
| books | |
| |> List.map .authors | |
| |> List.concat | |
| |> Set.fromList | |
| |> Set.size | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment