Slides for the second lesson in my PureScript lunch-n-learn series. The topic is "Records and Functions," and the material builds upon chapter 3 of "PureScript by Example."
String , city :: String , state :: String } type Entry = { firstName :: String , lastName :: String , address :: Address } type AddressBook = List Entry Use the type keyword to define a type
String , city :: String , state :: String } type Entry = { firstName :: String , lastName :: String , address :: Address } type AddressBook = List Entry Use the type keyword to define a type Here we quantify the types of our record fields
String , city :: String , state :: String } type Entry = { firstName :: String , lastName :: String , address :: Address } type AddressBook = List Entry Use the type keyword to define a type Here we quantify the types of our record fields Types can be nested
String , city :: String , state :: String } type Entry = { firstName :: String , lastName :: String , address :: Address } type AddressBook = List Entry Use the type keyword to define a type Here we quantify the types of our record fields Types can be nested Linked list of Entries
call a function, supply the function name and all parameters, separated by spaces • Functions are left-associative • All functions are curried • Use parens (or the $ operator) to nest calls as needed • Translate directly to JavaScript functions Functions
call a function, supply the function name and all parameters, separated by spaces • Functions are left-associative • All functions are curried • Use parens (or the $ operator) to nest calls as needed • Translate directly to JavaScript functions Functions
call a function, supply the function name and all parameters, separated by spaces • Functions are left-associative • All functions are curried • Use parens (or the $ operator) to nest calls as needed • Translate directly to JavaScript functions Functions
call a function, supply the function name and all parameters, separated by spaces • Functions are left-associative • All functions are curried • Use parens (or the $ operator) to nest calls as needed • Translate directly to JavaScript functions Functions
call a function, supply the function name and all parameters, separated by spaces • Functions are left-associative • All functions are curried • Use parens (or the $ operator) to nest calls as needed • Translate directly to JavaScript functions Functions
call a function, supply the function name and all parameters, separated by spaces • Functions are left-associative • All functions are curried • Use parens (or the $ operator) to nest calls as needed • Translate directly to JavaScript functions Functions
first entry in the -- AddressBook that contains the given first and last names. Since it may be -- the case that no entries match, this function is "safe" and return Maybe Entry. findEntry firstName lastName book = head $ filter containsName book where containsName entry = entry.firstName == firstName && entry.lastName == lastName
first entry in the -- AddressBook that contains the given first and last names. Since it may be -- the case that no entries match, this function is "safe" and return Maybe Entry. findEntry firstName lastName = head <<< filter containsName where containsName entry = entry.firstName == firstName && entry.lastName == lastName
first entry in the -- AddressBook that contains the given first and last names. Since it may be -- the case that no entries match, this function is "safe" and return Maybe Entry. findEntry firstName lastName = filter containsName >>> head where containsName entry = entry.firstName == firstName && entry.lastName == lastName