Skip to content

Instantly share code, notes, and snippets.

@ufocoder
Created November 4, 2018 20:27
Show Gist options
  • Select an option

  • Save ufocoder/45d16524932a5256b55c1ae0dcf583eb to your computer and use it in GitHub Desktop.

Select an option

Save ufocoder/45d16524932a5256b55c1ae0dcf583eb to your computer and use it in GitHub Desktop.
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