A comprehensive step-by-step guide Programming in Scala Third Edition Updated for Scala 2.12 Martin Odersky Lex Spoon artima Bill Venners Cover·Overview·Contents·Discuss·Suggest·Glossary·Index Praise for the earlier editions of Programming in Scala Programming in Scala is probably one of the best programming books I’veeverread. Ilikethewritingstyle,thebrevity,andthethoroughexplana- tions. The book seems to answer every question as it enters my mind—it’s always one step ahead of me. The authors don’t just give you some code andtakethingsforgranted. Theygiveyouthemeatsoyoureallyunderstand what’sgoingon. Ireallylikethat. -KenEgervari,ChiefSoftwareArchitect Programming in Scala is clearly written, thorough, and easy to follow. It has great examples and useful tips throughout. It has enabled our organi- zation to ramp up on the Scala language quickly and efficiently. This book is great for any programmer who is trying to wrap their head around the flexibilityandeleganceoftheScalalanguage. -LarryMorroni,Owner,MorroniTechnologies,Inc. The Programming in Scala book serves as an excellent tutorial to the Scala language. Working through the book, it flows well with each chapter buildingonconceptsandexamplesdescribedinearlierones. Thebooktakes care to explain the language constructs in depth, often providing examples of how the language differs from Java. As well as the main language, there isalsosomecoverageoflibrariessuchascontainersandactors. I have found the book really easy to work through, and it is probably oneofthebetterwrittentechnicalbooksIhavereadrecently. Ireallywould recommendthisbooktoanyprogrammerwantingtofindoutmoreaboutthe Scalalanguage. -MatthewTodd Cover·Overview·Contents·Discuss·Suggest·Glossary·Index iii IamamazedbytheeffortundertakenbytheauthorsofProgrammingin Scala. ThisbookisaninvaluableguidetowhatIliketocallScalathePlat- form: avehicletobettercoding,aconstantinspirationforscalablesoftware design and implementation. If only I had Scala in its present mature state andthisbookonmydeskbackin2003,whenco-designingandimplement- ingpartsoftheAthens2004OlympicGamesPortalinfrastructure! To all readers: No matter what your programming background is, I feel you will find programming in Scala liberating and this book will be a loyal friendinthejourney. -ChristosKKLoverdos,SoftwareConsultant,Researcher ProgramminginScalaisasuperbin-depthintroductiontoScala,andit’s alsoanexcellentreference. I’dsaythatitoccupiesaprominentplaceonmy bookshelf,exceptthatI’mstillcarryingitaroundwithmenearlyeverywhere Igo. -BrianClapper,President,ArdenTex,Inc. Greatbook,wellwrittenwiththoughtfulexamples. Iwouldrecommend ittobothseasonedprogrammersandnewbies. -HowardLovatt The book Programming in Scala is not only about how, but more im- portantly,whytodevelopprogramsinthisnewprogramminglanguage. The book’s pragmatic approach in introducing the power of combining object- oriented and functional programming leaves the reader without any doubts astowhatScalareallyis. -Dr. ErvinVarga,CEO/founder,EXPROI.T.Consulting ThisisagreatintroductiontofunctionalprogrammingforOOprogram- mers. Learning about FP was my main goal, but I also got acquainted with someniceScalasurpriseslikecaseclassesandpatternmatching. Scalaisan intriguinglanguageandthisbookcoversitwell. There’s always a fine line to walk in a language introduction book be- tween giving too much or not enough information. I find Programming in Scalatoachieveaperfectbalance. -JeffHeon,ProgrammerAnalyst Cover·Overview·Contents·Discuss·Suggest·Glossary·Index iv I bought an early electronic version of the Programming in Scala book, by Odersky, Spoon, and Venners, and I was immediately a fan. In addition to the fact that it contains the most comprehensive information about the language,thereareafewkeyfeaturesoftheelectronicformatthatimpressed me. I have never seen links used as well in a PDF, not just for bookmarks, but also providing active links from the table of contents and index. I don’t know why more authors don’t use this feature, because it’s really a joy for the reader. Another feature which I was impressed with was links to the forums(“Discuss”)andawaytosendcomments(“Suggest”)totheauthors via email. The comments feature by itself isn’t all that uncommon, but the simpleinclusionofapagenumberinwhatisgeneratedtosendtotheauthors is valuable for both the authors and readers. I contributed more comments thanIwouldhaveiftheprocesswouldhavebeenmorearduous. Read Programming in Scala for the content, but if you’re reading the electronic version, definitely take advantage of the digital features that the authorstookthecaretobuildin! -DianneMarsh,Founder/SoftwareConsultant,SRTSolutions Lucidity and technical completeness are hallmarks of any well-written book,andIcongratulateMartinOdersky,LexSpoon,andBillVennersona jobindeedverywelldone! TheProgramminginScalabookstartsbysetting a strong foundation with the basic concepts and ramps up the user to an intermediate level & beyond. This book is certainly a must buy for anyone aspiringtolearnScala. -JaganNambi,EnterpriseArchitecture,GMACFinancialServices Programming in Scala is a pleasure to read. This is one of those well- writtentechnicalbooksthatprovidedeepandcomprehensivecoverageofthe subjectinanexceptionallyconciseandelegantmanner. Thebookisorganizedinaverynaturalandlogicalway. Itisequallywell suitedforacurioustechnologistwhojustwantstostayontopofthecurrent trends and a professional seeking deep understanding of the language core features and its design rationales. I highly recommend it to all interested in functional programming in general. For Scala developers, this book is unconditionallyamust-read. -IgorKhlystov,SoftwareArchitect/LeadProgrammer,GreystoneInc. Cover·Overview·Contents·Discuss·Suggest·Glossary·Index v ThebookProgramminginScalaoutrightoozesthehugeamountofhard work that has gone into it. I’ve never read a tutorial-style book before that accomplishestobeintroductoryyetcomprehensive: intheir(misguided)at- tempttobeapproachableandnot“confuse”thereader,mosttutorialssilently ignore aspects of a subject that are too advanced for the current discussion. Thisleavesaverybadtaste,asonecanneverbesureastotheunderstanding one has achieved. There is always some residual “magic” that hasn’t been explained and cannot be judged at all by the reader. This book never does that, it never takes anything for granted: every detail is either sufficiently explained or a reference to a later explanation is given. Indeed, the text is extensivelycross-referencedandindexed,sothatformingacompletepicture ofacomplextopicisrelativelyeasy. -GeraldLoeffler,EnterpriseJavaArchitect ProgramminginScalabyMartinOdersky,LexSpoon,andBillVenners: intimeswheregoodprogrammingbooksarerare,thisexcellentintroduction for intermediate programmers really stands out. You’ll find everything here youneedtolearnthispromisinglanguage. -ChristianNeukirchen Cover·Overview·Contents·Discuss·Suggest·Glossary·Index Programming in Scala Third Edition Cover·Overview·Contents·Discuss·Suggest·Glossary·Index Programming in Scala Third Edition Martin Odersky, Lex Spoon, Bill Venners artima ARTIMAPRESS WALNUTCREEK,CALIFORNIA Cover·Overview·Contents·Discuss·Suggest·Glossary·Index viii ProgramminginScala ThirdEdition MartinOderskyisthecreatoroftheScalalanguageandaprofessoratEPFLin Lausanne,Switzerland. LexSpoonworkedonScalafortwoyearsasapost-doc withMartinOdersky. BillVennersispresidentofArtima,Inc. ArtimaPressisanimprintofArtima,Inc. P.O.Box305,WalnutCreek,California94597 Copyright©2007-2016MartinOdersky,LexSpoon,andBillVenners. Allrightsreserved. FirsteditionpublishedasPrePrint™eBook2007 Firsteditionpublished2008 SecondeditionpublishedasPrePrint™eBook2010 Secondeditionpublished2010 ThirdeditionpublishedasPrePrint™eBook2016 Thirdeditionpublished2016 BuilddateofthisimpressionApril6,2016 ProducedintheUnitedStatesofAmerica Nopartofthispublicationmaybereproduced,modified,distributed,storedina retrievalsystem,republished,displayed,orperformed,forcommercialor noncommercialpurposesorforcompensationofanykindwithoutpriorwritten permissionfromArtima,Inc. Allinformationandmaterialsinthisbookareprovided"asis"andwithout warrantyofanykind. Theterm“Artima”andtheArtimalogoaretrademarksorregisteredtrademarksof Artima,Inc. Allothercompanyand/orproductnamesmaybetrademarksor registeredtrademarksoftheirowners. Cover·Overview·Contents·Discuss·Suggest·Glossary·Index toNastaran-M.O. toFay-L.S. toSiew-B.V. Cover·Overview·Contents·Discuss·Suggest·Glossary·Index Overview Contents xi ListofFigures xxi ListofTables xxiii ListofListings xxv Foreword xxxii Acknowledgments xxxiv Introduction xxxvii 1. AScalableLanguage 45 2. FirstStepsinScala 64 3. NextStepsinScala 77 4. ClassesandObjects 99 5. BasicTypesandOperations 112 6. FunctionalObjects 135 7. Built-inControlStructures 155 8. FunctionsandClosures 180 9. ControlAbstraction 203 10. CompositionandInheritance 218 11. Scala’sHierarchy 246 12. Traits 257 13. PackagesandImports 276 14. AssertionsandTests 294 15. CaseClassesandPatternMatching 306 16. WorkingwithLists 340 17. WorkingwithOtherCollections 373 18. MutableObjects 395 19. TypeParameterization 418 20. AbstractMembers 443 21. ImplicitConversionsandParameters 474 22. ImplementingLists 499 23. ForExpressionsRevisited 512 24. CollectionsinDepth 528 25. TheArchitectureofScalaCollections 597 26. Extractors 621 27. Annotations 637 28. WorkingwithXML 645 29. ModularProgrammingUsingObjects 659 30. ObjectEquality 674 31. CombiningScalaandJava 698 32. FuturesandConcurrency 714 33. CombinatorParsing 736 34. GUIProgramming 765 35. TheSCellsSpreadsheet 777 A. ScalaScriptsonUnixandWindows 802 Glossary 803 Bibliography 819 AbouttheAuthors 822 Index 823 Cover·Overview·Contents·Discuss·Suggest·Glossary·Index
Description: