Errata

Becoming Functional

Errata for Becoming Functional

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF Page ix
last line -1

These
methods, hoever, (think it should be however) also not convinced it backs sense either.

john white  Sep 12, 2014 
Mobi Example 4-6

It seems to me your Example 4-6 `eachEnabledContact closure` does not do what it claims to do.

Your findAll does { customer.enabled && customer.contract.enabled } and there is no contact.enabled check anywhere

I think this is a simple case of accidentally mixing up contact and cont*r*act (typo)

Lauri Piisang  Mar 08, 2018 
PDF Page 8
3rd code example

"cutomer" should be "customer"

also found at:
page 15, last paragraph, second line
page 39, example 3-28 (two times)
page 40, example 3-29 (two times on the two last lines)
page 41, example 3-29 (six times)
page 85, example 7-8 (eight times)

Christopher Kluwe  Jul 11, 2014 
PDF Page 9
bottom

There is a code:
public static List<String> getEnabledCustomerField(String field) {
ArrayList<String> outList = new ArrayList<String>();
for(Customer customer : Customer.allCustomers) {
if(customer.enabled) {
if(field == "name") {
outList.add(customer.name);
} else if(field == "state") {
outList.add(customer.state);
} else if(field == "primaryContact") {
outList.add(customer.primaryContact);
} else if(field == "domain") {
outList.add(customer.domain);
} else if(field == "address") {
outList.add(customer.address);
} else {
throw new IllegalArgumentException("Unknown field");
}
}
}
return outList;
}

Shouldnt we use .equals() for comparising Strings instead of equal sign (==)?

Anonymous  Oct 12, 2014 
Printed Page 15
top

The definition of the static private class
static private class CustomerAsCustomer implements Function1<Customer, Customer> {
public String call(Customer customer) { return customer; }
}

should must likely be
static private class CustomerAsCustomer implements Function1<Customer, String> {
public String call(Customer customer) { return customer; }
}

Otherwise the return type of the method call would be wrong!

Josef Joller  Aug 12, 2014 
Printed Page 15
bottom

static private class CustomerAsCustomer implements Function1<Customer, Customer> {
public String call(Customer customer) { return customer; }
}

on the bottom of page 15 should, as said in the text above the code, a customer object: - not a string
static private class CustomerAsCustomer implements Function1<Customer, Customer> {
public Customer call(Customer customer) { return customer; }
}

Josef Joller  Aug 12, 2014 
PDF Page 15,
top and bottom

There is a function:
static private class CustomerAsCustomer implements Function1<Customer, Customer> {
public String call(Customer customer) { return customer; }
}

which do not compile, as the return type of call() is wrong and should be Customer:

static private class CustomerAsCustomer implements Function1<Customer, Customer> {
public Customer call(Customer customer) { return customer; }
}

Wojciech Jancz  Oct 12, 2014 
Printed Page 17
middle

In the text at the top the following method is defined (Ex 2-13):
public static List<String> getEnabledCustomerAddresses() {
return Customer.getEnabledCustomerField(new Function1<Customer,String>() {
public String call(Customer customer) { return customer.address; }
});
}

later in Ex 2-14
public static List<String> getEnabledCustomerAddresses() {
return Customer.getEnabledCustomerField(new Function1<Customer,String>() {
public String call(Customer customer) { return customer.addresses; }
});
}
However, the field addresses is undefined.
Probably it should be address, as above.

Josef Joller  Aug 12, 2014 
Printed Page 40
Schweiz

Code 3-29

public Customer setCustomerId(Integer customer_id) {
this.customer_id = customer_id;
return this;
}

customer_id is not a customer field
id is the customer id.
Probably the code should read
public Customer setCustomerId(Integer customer_id) {
this.id = customer_id;
return this;
}

Josef Joller  Aug 12, 2014 
Printed Page 50
Example 4-9. Immutable Contract class

after (p 50 at the bottom)
public final Boolean enabled = true;

we cannot set enabled as in the code on p 51 (top)
public Contract(Calendar begin_date, Boolean enabled) {
this.begin_date = begin_date;
this.end_date = this.begin_date.getInstance();
this.end_date.setTimeInMillis(this.begin_date.getTimeInMillis());
this.end_date.add(Calendar.YEAR, 2);
this.enabled = enabled;
}
If we want to be able to set the field, then it cannot be final AND initialized.
Probably the code (on P 50) should be
public final Boolean enabled;;
Then the value can be initialized (exactly once).

Josef Joller  Aug 12, 2014 
PDF Page 72
example 6-12

in Scala example:
contact -> contact.enabled
should be
contact => contact.enabled

Christopher Kluwe  Jul 11, 2014 
Printed Page 80
Example 7-3. Contact.java file

On page 80 the followinf field are declared and initialized (final)

public final Integer contact_id = 0;
public final String firstName = "";
public final String lastName = "";
public final String email = "";
public final Boolean enabled = true;

on the following constructor (p 80 bottom)
public Contact(Integer contact_id,
String firstName,
String lastName,
String email,
Boolean enabled) {
this.contact_id = contact_id;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.enabled = enabled;
}
the final AND initialized filed are overwritten, which is not possible.
Probably the filed should not be initialized in their declaration (p 80)

public final Integer contact_id;
public final String firstName;
public final String lastName;
public final String email;
public final Boolean enabled;

or the final attribute has to be removed.

Josef Joller  Aug 12, 2014 
Printed Page 81
Example 7-3. Contact.java file

public void sendEmail() {
println("Sending Email")
}

should probably be
public void sendEmail() {
System.out. println("Sending Email")
}

Josef Joller  Aug 12, 2014 
PDF Page 84
1st Heading

Throughout the chapter the author is pretty lax in separating the terms statement and expression.

A statement is the smallest unit of command one can formulate in any given language and does not necessarily yield a result. An expression on the other hand does. So an expression is a statement, but the reverse is not necessarily true.

The headline "Everything Is a Statement" should be called "Everything Is an Expression" - especially in the context of Scala, where Martin Odersky (creator of Scala) writes: "Scala is an expression-oriented language" [Scala By Example, http://www.scala-lang.org/docu/files/ScalaByExample.pdf, page 6]

The same goes for the "everything is a statement" on page 87, last paragraph and page 90, last paragraph. In every imperative (including most object oriented) and functional language "everything is a statement" - but only in the latter everything (well, almost) is also an expression.

Throughout the chapter it should be checked, whether the term expression is a better fit than the term statement. Sometimes it is right to favour the latter (e.g. in compound statement), often it would be advisable to use the former - in my opinion.

Christopher Kluwe  Jul 11, 2014 
Printed Page 114
class None<T>

public class None<T> implements Option<T> {
public T getOrElse(T defObj) {
return obj;
}

should be without the get...
public class None<T> implements Option<T> {
public T getOrElse(T obj) {
return obj;
}
(as on line 10:
"a getOrElse(T obj) method on the Option interface...")

Josef Joller  Aug 12, 2014 
ePub Page 143
All of Chapter 7

In functional programming, it is common to make a distinction between "statements" and "expressions". The usual convention is that an expressions (like functions) can be evaluated to a value, while a statement e.g. println("Foo").

In a FP language like Scala, an "if" expression is evaluated to a value, as in the examples in this book, while apparent statements things like println() are actually expressions that return Unit.

A Java "if" statement has no value unless one is explicitly returned, and println() does not return anything.

This book (which is otherwise excellent) seems to get this the wrong way around throughout Chapter 7 e.g. on p. 151 the section header is "Everything Is a Statement", but in fact in functional programming "everything is an expression".

Anonymous  Aug 29, 2014