Created
February 21, 2015 19:17
-
-
Save killtheliterate/21706a7de1354fad2c03 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
module Data.PhoneBook where | |
import Data.List | |
import Data.Maybe | |
import Control.Plus (empty) | |
type Entry = { firstName :: String, lastName :: String, phone :: String } | |
type PhoneBook = List Entry | |
showEntry :: Entry -> String | |
showEntry entry = entry.lastName ++ ", " ++ | |
entry.firstName ++ ": " ++ | |
entry.phone | |
emptyBook :: PhoneBook | |
emptyBook = empty | |
insertEntry :: Entry -> PhoneBook -> PhoneBook | |
insertEntry = Cons | |
filter :: (Entry -> Boolean) -> PhoneBook -> PhoneBook | |
head :: PhoneBook -> Maybe Entry | |
findEntry :: String -> String -> PhoneBook -> Maybe Entry | |
findEntry firstName lastName book = head <<< filter filterEntry | |
where | |
filterEntry :: Entry -> Boolean | |
filterEntry entry = entry.firstName == firstName && entry.lastName == lastName | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment