TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types...

Post on 27-Dec-2019

6 views 0 download

Transcript of TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types...

x 10,000

x 1,000,000

x 1000

Assembler

Procedural

Object

Oriented

Managed

λ

First class functions

Immutable

data

Referential

transparency

Algebraic data types

Type

inference

Pattern

matching

function sumOfSquares(a) {var result = 0;for (var i = 0; i < a.length; i++) {

result += a[i] * a[i];}return result;

}

function sumOfSquares(a) {if (a.length === 0) {

return 0;}else {

return a[0] * a[0] + sumOfSquares(a.slice(1));}

}

let rec sumOfSquares a =match a with| [] -> 0| h :: t -> h * h + sumOfSquares t

function sumOfSquares(a) {return a.reduce((x, y) => x + y * y, 0);

}

const products = getProductList();const maxPrice = 100;const result = products

.filter(p => p.price < maxPrice)

.map(p => p.name);

ES7 (2016)

ES6 (2015)

ES5 (2009)

ES3 (1999)

var data = downloadData(...);processData(data);

downloadDataAsync(... , data => {processData(data);

});

downloadDataAsync processData

processDatadownloadData

ThreadPool.run(() => {var data = downloadData(...);processData(data);

});

processDatadownloadData

function doWork(...) {return webService1(...).then(data1 => {

return webService2(...).then(data2 => {var result = doSomething(data1, data2);return result;

});});

}

async function doWork(...) {var data1 = await webService1(...);var data2 = await webService2(...);var result = doSomething(data1, data2);return result;

}

CompilerCompilerSource code

Source code

Source

File

Source codeSource code

Executable

Code

Class

Field

public Foo

private

string

X

Statement completion Code navigation

Refactoring Outlining

JSON