Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Collection Methods10-3-2011Opening DiscussionDo you have any questions about the quiz?Minute essay comments:How long do you have to correct assignments?There will be a study guide. The test covers everything we have done.I did write the spreadsheet and the quiz average is dropping the lowest.Looking back and moving forward.2-D arrays = Array[Array[???]]Use zip to work on two things at once.MoreEverything we are doing works on both Lists and Arrays.Examples at the end of class today.Standard MethodsThere are lots of methods on collections. The API can help us see all of them.Part of collections: drop, init, last, slice, splitAt, take, takeRightBoolean tests: contains, endsWith, isEmpty, nonEmpty, startsWithSearching: indexOf, lastIndexOfOther: mkString, reverse, zip, zipWithIndexOther MethodsIf the elements in a list support addition or multiplication, you can use the sum and product methods.If they are ordered you can do min and max.Having sum and length makes averages really easy.With min you can even drop a grade easily.Higher Order MethodsThe most powerful methods are ones you can pass functions into.exists, forall – Boolean checks like for math.filter, partition – separate collection based on Boolean.map – apply function to all the elements.reduceLeft – apply function moving through collectionfoldLeft – apply function moving through, but allows initial value so it can return a different type. This is curried.Let's Put These Into ActionI want to spend the rest of the class time playing with these methods and seeing what we can do with them.A String is a collection so you can do these things with a String as well.String also has a method called split.BLS dataftp://ftp.bls.gov/pub/time.series/la/Minute EssayWhat questions do you have?Getting your head around the higher-order methods can take time. Practice is your best
View Full Document