The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Based on the code given by following web site

I modified the code in Listing 7.2 as follow:

let convertImageTo3D (sourceImage: string) (destinationImage:string) =
let bitmap = Bitmap.FromFile(sourceImage) smilie> Bitmap
let bmp = new Bitmap(bitmap.Width, bitmap.Height)
[| for y in 0..bitmap.Height - 1 do
for x in 0..bitmap.Width - 1 -> x, y, bitmap.GetPixel(x,y) |]
fun (x,y,c) ->
let shiftx =
if x + 20 >= bitmap.Width then bitmap.Width-1
else x + 20
let c1 = bitmap.GetPixel(shiftx, y)
in x,y,Color.FromArgb(int c1.R, int c.G, int c.B))
|> Array.iter(fun (x,y,c) -> bmp.SetPixel(x,y,c))
bmp.Save(destinationImage, ImageFormat.Jpeg)

let setGrayScale (sourceImage: string) (destinationImage:string) =
let bitmap = Bitmap.FromFile(sourceImage) smilie> Bitmap
let bmp = new Bitmap(bitmap.Width, bitmap.Height)
[| for y in 0..bitmap.Height - 1 do
for x in 0..bitmap.Width - 1 -> x, y, bitmap.GetPixel(x,y) |]
fun (x,y,c) ->
let gray = int(0.299 * float c.R + 0.587 * float c.G + 0.114 * float c.B)
in x,y,Color.FromArgb(gray, gray, gray))
|> Array.iter(fun (x,y,c) -> bmp.SetPixel(x,y,c))
bmp.Save(destinationImage, ImageFormat.Jpeg)

let setRedScale (sourceImage: string) (destinationImage:string) =
let bitmap = Bitmap.FromFile(sourceImage) smilie> Bitmap
let bmp = new Bitmap(bitmap.Width, bitmap.Height)
[| for y in 0..bitmap.Height - 1 do
for x in 0..bitmap.Width - 1 -> x, y, bitmap.GetPixel(x,y) |]
|> (x,y,c) -> x,y,Color.FromArgb(int c.R, 0, 0))
|> Array.iter(fun (x,y,c) -> bmp.SetPixel(x,y,c))
bmp.Save(destinationImage, ImageFormat.Jpeg)

The code looks more functional!
I wrote following code to test the swap function (inside static Main method):

Atom<ImmutableDictionary<Guid, string>> onlineUsers =
new Atom<ImmutableDictionary<Guid, string>>(ImmutableDictionary<Guid, string>.Empty);

Guid connectionId = Guid.NewGuid();

var temp = onlineUsers.Value;

if (onlineUsers.Swap(d =>
if (d.ContainsKey(connectionId)) return d;
return d.Add(connectionId, "Winson");
}) != temp)
Console.WriteLine("Register User");

var temp2 = onlineUsers.Value;
Guid connectionId2 = Guid.NewGuid();
if (onlineUsers.Swap(d =>
if (d.ContainsKey(connectionId2)) return d;
return d.Add(connectionId2, "Dick");
}) != temp2)
Console.WriteLine("Register User");


If the swap function return "value", above code will print "Register User" message twice which is the expected result.
The Javascript Codes discussed in chapter 4 do not match from those that

download from the Git repository - "complete-isomorphic-example.git".

I tried to update the codes as attached which incorporate with 'React-Router v4'

The package.json file will be updated as follow:

"react-router-dom": "^4.2.2",

Hope this could provide some insight to those looking for 'React-Router v4' codes.
In version 4, chapter 1 is as same as chapter 2!
Will you update the topic of React Router to React Router version 4 because version 4 syntax is quite different from version 3?

the code should be

const countryPath = ['address','country']; <- original text 'city' is undefined field
const countryLens = R.lens(R.path(countryPath), R.assocPath(countryPath));


I totally agree that JSON is more clean and affordable.

The material discussed in Chapter 4 is also not applicable to latest version of dotnet core

Will you also discuss dotnet standard library v2.0 and the difference between v1.6 and v2.0?
Fail to run the test in Listing 8.8

Then, I tried to run following code in console app:

var t = f(1);
var k = List(1).Bind(f);


The result shown as follow:


Is it because f(t) and List(t).Bind(f) are two different data types that caused the test fail?

Code listing in p175 missing App Component Class Definition:

Insert following class definition work as expected:

class AppComponent {
@Input() stockSymbol: string = "";
@Input() price: number = 0;
priceQuoteHandler(source) {
this.stockSymbol = source.stockSymbol;
this.price = source.lastPrice;

Functional Implementation of Validate should be:

public bool Validate(Transfer request)
=> accounts.Get(request.DebitedAccountId)
.Map(account => account.canCover(request.Amount))
.GetOrElse(() => false);

We need to pass function back to GetOrElse since fallback of GetOrElse is defined as:

Func<T> fallback
Would you please explain the RunExample<T> extension code?

Why we could not view the result of async task when subscribe to SubscribeConsole and we need to subscribe to RunExample?
The ForEach code in listing 4.3.1 did not handle the situation that the Option may contain a List data Type. How can we handle this kind of data type?
How to merge the Option code on p65 to the Option Code in Listing 3.2?

Why the Option Code on p65 implements IEquatable interface?
I'm referring to the first part of Chapter 3.

I think the step discussed in Section 3.6.1 should be put at the beginning of this chapter so that readers could aware that it needs to take this step before

starting to test Angular 2 router code

I also find out minor mistake in the book, like in page 41, the 4th paragraph which discussed about Alpha version of Angular and it should be Beta version now

Another one is *ng-for which should be *ngFor (the home controller code) and NgFor should be import from 'angular2/common'
In order to test the code of Chapter 3, remember to include following script tag in the main.html:

<script src="node_modules/angular2/bundles/"></script>

Otherwise, the browser will return 404 error:

'angular2/router' could not be found
Several things need to be changed, otherwise the auction web site will fail to run when using with angular2.0.0-beta.0:

Modify the Index.html as follow:

<script src="node_modules/typescript/lib/typescript.js"></script>
<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/"></script>
<script src="config.js"></script> <!--2-->

2. Modify the application.ts as follow:

import {Component} from 'angular2/core';
import {NgFor} from 'angular2/common'

Component class is no longer reference from 'angular2/angular2'

3. Modify the application.html as follow:

change *ng-for to *ngFor

4. Modify all ts file to reference the component class to 'angular2/core'

5. Modify the star.ts file to import {NgFor} from 'angular2/common'

6. Modify the stars.html file as follow:

change *ng-for to *ngFor
Listing 7.19 will not work since _showError function belongs to another module

My approach will be like this:

1. Make a sub-directory called utility under app_server

2. Create a js file under this sub-directory with code like this:
var getLocationInfo = function(req,res,errFn,callback) { ... }

errFn refer to the error function

So the else clause will become:

3. Export the module: = function(req, res, fn, errFn){
getLocationInfo(req, res, errFn, function(req, res, responseData) {
fn(req, res, responseData);

4. Then modify the location.js like this:

var locinfo = require("../utility/locinfo");


/* Get 'Location Info' page */
module.exports.locationInfo = function(req,res) {,res,renderDetailPage,_showError);

/* Get 'Add Review' page */
module.exports.addReview = function(req,res) {,res,renderReviewForm,_showError);

The code looks clean and DRY!

If I remark following script section in index.html:

<script src="/lib/"></script>

the web site will fail to start up with error like this:

Uncaught Uncaught SyntaxError: Unexpected token <
Evaluating http://localhost:8080/angular2/angular2

However, I'm not sure which mongodb javascript file to be put into the script section.

I think it is worthwhile to discuss how to integrate Augular2 with MongoDB since
this is quite common configuration
DBService code:

/// <reference path="../../typings/tsd.d.ts" />
import { StockInterface } from '../services/stocks';
import mongodb = require("mongodb");

export class dbService {
server: mongodb.Server;
client: mongodb.Db;
db: mongodb.Db;

constructor() {
this.server = new mongodb.Server(localhost, 27017, { auto_reconnect: true });
this.client = new mongodb.Db('stock', this.server, { w: 1 }); {});

In dashboard.ts:

import {dbService} from '../services/dbsrv';

export class Dashboard {
stocks: Array<StockInterface>;
symbols: Array<string>;
dbsrv: dbService;

constructor(service: StocksService) {
this.symbols = service.get();

service.load(this.symbols).subscribe(stocks => this.stocks = stocks);

dbsrv = new dbService();

Following errors shown in the browser console:

XHR finished loading: GET "http://localhost:8080/mongodb". system.src.js:1057
Uncaught SyntaxError: Unexpected token <

How can I resolve this error?
Sure. Thanks
I used MongoDB as the persistent storage. I've defined a db service class like this:

export class dbService {
server: mongodb.Server;
client: mongodb.Db;
db: mongodb.Db;
constructor() {

How to initialize the db service class? Inside App class or Dashboard Class?
Here is my code try to achieve this requirement:

__.difference(__.allKeys(bobFavorites),req.access_token.scope).forEach( function(item) {
if (bobFavorites[item])
delete bobFavorites[item];

Any comment is welcome!
After reading Chapter 1, I found out that the material discussed is quite similar to this book:

Angular 2 Development with TypeScript

Will other chapters also be the similar case?
The code in page 89 should be:

Executable program = foldLeft(pricesIncludingShipping, ez,
e -> d -> compose.apply(e).apply( () -> printWith2decimals.apply(d)));

not compose.apply(d).apply(()->printWith2decimals.apply(d))); since d is not executable type and could not be applied in first part
Addition problems found:

Appendix B section B.1.1 - the link for downloading amelia theme should be

Chapter 4 - p95 Listing 4.5 - the css class navbar-default could not be found. I change it to navbar-inner

Chapter 4 - p100 - in order to show the star rating, I've to include original bootstrap.min.css before amelia.bootstrap.min.css
p17, figure 2.4 the one at right hand side is incorrect

p18, Listing 18, I think it should be:

#B - function code is the code contained within function
#A - global code is the code outside function

p23, last word of 5th line should be addEventListenerMethod

I forgot to put the static import statement in the java code. After I put back the static import statement,

the code works!

The compiler stated error in following code:

mcase( () -> success(s) )

The method mcase(() -> {}) is undefined for the type emailValidation

How can I resolve this error?
The success code of "Open" method should be:

The if-clause of "Close" method should be:
if (cd before account.dateOfOpen.get)

At right hand side of figure 2.1, why the codomain did not contain fractional number so that the function f(x) = x/2 has corresponding element in the codomain?
In figure 1.6, why message from printing office is not simultaneously send to all ticket agents?

What happen if one of the ticket agents fail to send message to next ticket agent?

It seems that all ticket agents are not running at the same time. Each one is running one after another.

In the code spa.js, what is the difference between

return { initModule: initModule };


return { initModule };