Skip to content

Instantly share code, notes, and snippets.

@killtheliterate
Created February 21, 2015 19:17
Show Gist options
  • Save killtheliterate/21706a7de1354fad2c03 to your computer and use it in GitHub Desktop.
Save killtheliterate/21706a7de1354fad2c03 to your computer and use it in GitHub Desktop.
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