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

58

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

Page 1: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 2: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 3: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 4: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

x 10,000

x 1,000,000

x 1000

Page 5: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 6: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

Assembler

Procedural

Object

Oriented

Managed

Page 7: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 8: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 9: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 10: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

λ

First class functions

Immutable

data

Referential

transparency

Algebraic data types

Type

inference

Pattern

matching

Page 11: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 12: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 13: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 14: TypeScript · λ 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;

}

Page 15: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

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

return 0;}else {

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

}

Page 16: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

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

Page 17: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

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

}

Page 18: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

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

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

.map(p => p.name);

Page 19: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 20: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 21: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 22: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 23: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 24: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 25: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 26: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 27: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

ES7 (2016)

ES6 (2015)

ES5 (2009)

ES3 (1999)

Page 28: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 29: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 30: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 31: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 32: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 33: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 34: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 35: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 36: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 37: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 38: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 39: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

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

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

});

downloadDataAsync processData

processDatadownloadData

Page 40: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

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

});

processDatadownloadData

Page 41: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 42: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

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

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

});});

}

Page 43: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

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

}

Page 44: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 45: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 46: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 47: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

CompilerCompilerSource code

Source code

Source

File

Source codeSource code

Executable

Code

Class

Field

public Foo

private

string

X

Statement completion Code navigation

Refactoring Outlining

Page 48: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 49: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 50: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 51: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching

JSON

Page 52: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 53: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 54: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 55: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 56: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 57: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching
Page 58: TypeScript · λ First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching