Functional Programming in Scala

By Paul Chiusano, Runar Bjarnason

Functional programming (FP) is a programming kind emphasizing features that go back constant and predictable effects despite a program's country. for this reason, useful code is less complicated to check and reuse, easier to parallelize, and no more susceptible to insects. Scala is an rising JVM language that provides powerful help for FP. Its everyday syntax and obvious interoperability with present Java libraries make Scala a great spot to begin studying FP.

Functional Programming in Scala is a significant instructional for programmers seeking to research FP and use it on the typical enterprise of coding. The publication courses readers from simple recommendations to complicated issues in a logical, concise, and transparent development. In it, they'll locate concrete examples and workouts that open up the realm of practical programming.

buy of the print booklet comes with a proposal of a unfastened PDF, ePub, and Kindle book from Manning. additionally on hand is all code from the book.

Show description

Preview of Functional Programming in Scala PDF

Best Computer Science books

Web Services, Service-Oriented Architectures, and Cloud Computing, Second Edition: The Savvy Manager's Guide (The Savvy Manager's Guides)

Internet providers, Service-Oriented Architectures, and Cloud Computing is a jargon-free, hugely illustrated clarification of ways to leverage the speedily multiplying companies on hand on the web. the way forward for enterprise is dependent upon software program brokers, cellular units, private and non-private clouds, colossal info, and different hugely hooked up expertise.

Software Engineering: Architecture-driven Software Development

Software program Engineering: Architecture-driven software program improvement is the 1st entire advisor to the underlying talents embodied within the IEEE's software program Engineering physique of information (SWEBOK) ordinary. criteria specialist Richard Schmidt explains the conventional software program engineering practices famous for constructing initiatives for presidency or company structures.

Platform Ecosystems: Aligning Architecture, Governance, and Strategy

Platform Ecosystems is a hands-on advisor that provides a whole roadmap for designing and orchestrating bright software program platform ecosystems. not like software program items which are controlled, the evolution of ecosystems and their myriad individuals has to be orchestrated via a considerate alignment of structure and governance.

Additional resources for Functional Programming in Scala

Show sample text content

ForumID=805 66 implies that the functionality could decide on to not evaluation a number of of its arguments. by contrast, a strict functionality consistently evaluates its arguments. Strict capabilities are the norm in such a lot programming languages and so much languages do not even supply how to outline non-strict features. until you inform it differently, any functionality definition in Scala can be strict (and the entire features we've got outlined thus far were strict). to illustrate, give some thought to the subsequent functionality: def square(x: Double): Double = x * x should you invoke square(41. zero + 1. zero) sq. will obtain the evaluated price of forty two. zero since it is strict. in the event you have been to invoke square(sys. error("failure")), you will get an exception, because the sys. error("failure") expression could be evaluated ahead of getting into the physique of sq.. even supposing we have not but discovered the syntax for indicating non-strictness in scala, you're in all probability accustomed to non-strictness as an idea. for instance, the Boolean features && and || are non-strict. you'll be used to taking into account && and || as integrated syntax, a part of the language, yet we will additionally give some thought to them as capabilities which could decide upon to not assessment their arguments. The functionality && takes Boolean arguments, yet in basic terms evaluates the second one argument if the 1st is correct: scala> fake && { println("!! "); real } // doesn't print something res0: Boolean = fake And || basically evaluates its moment argument if the 1st is fake: scala> precise || { println("!! ") // does not print whatever both } res1: Boolean = precise one other instance of non-strictness is the if keep watch over build in Scala: val outcome = if (input. isEmpty) sys. error("empty input") else enter The if language build may be considered a functionality accepting 3 parameters: a situation of sort Boolean, an expression of a few style A to ©Manning guides Co. We welcome reader reviews approximately something within the manuscript — except typos and different basic blunders. those might be wiped clean up in the course of creation of the ebook through copyeditors and proofreaders. authorized to Leonardo Urbina http://www. manning-sandbox. com/forum. jspa? forumID=805 67 go back within the case that the situation is correct, and one other expression of an analogous style A to come if the is fake. This if functionality will be non-strict, because it won't overview all of its arguments. To be extra specified, we'd say that the if functionality is strict in its parameter, because it will regularly overview the situation to figure out which department to take, and non-strict within the branches for the real and fake instances, because it will basically overview one or the opposite in response to the situation. In Scala, we will be able to write non-strict capabilities by means of accepting a few of our arguments unevaluated, utilizing the next syntax: def if2[A](cond: Boolean, onTrue: => A, onFalse: => A): A = if (cond) onTrue else onFalse The arguments we wish to go unevaluated have => instantly prior to their sort. within the physique of the functionality, we don't have to do something to guage a controversy annotated with =>.

Download PDF sample

Rated 4.07 of 5 – based on 40 votes