index

Symbols

[[DefineOwnProperty]] 53

[[Get]] 212, 215

[[Scope]] 90

[[Set]] property 53-54

#precisionRound method 40

A

abstract operation 203

add function 91, 93, 98

address parameter 110

ADTs (Algebraic Data Types)

kinds of 131-132

record type 131-132

AMD (Asynchronous Module Definition) 159

applyIfNotNull function 118

arguments of a function 95

Array API 121

Array method 10, 99, 118, 120, 122, 124, 127, 131, 201-202, 273, 276, 302

Array object 262

Array#{map, filter, reduce} method 130

Array#concat method 199

Array#filter method 286

Array#flatMap method 109

Array#map method 116, 125-126, 202

Array#pop method 126

Array#reduce method 85

Array.of method 119-120

Array.prototype method 75

Array.prototype.flat 108, 122

Array.prototype.flatMap 122-123

 

Array.prototype.map(f) method 110

Array.prototype.pop method 119

assemble function 88-89, 96-97

associativity 128

async function 177, 256, 258-259, 266

async generators 269-272

async keyword 250

async/await feature 14, 20, 194, 249-252

async iteration 252-257

top-level await 257-259

Asynchronous Module Definition (AMD) 159

@@asyncIterator symbol 210, 255, 259

autohashed blocks 216-217

await 177, 253, 255, 258-259

B

babel-cli 307

Babel, configuring 306-307

backpack 8

balance method 106-107

balanceOf method 109

BigInt function 218

bind operator 5, 88

BitcoinService function 165, 167, 173, 194, 242

BitcoinService.serializeLedger function 196

Block class 57, 66, 100-101, 146, 149, 164, 173-174, 180, 194, 196, 207, 245-246, 263, 272-273, 311, 314-315, 318, 322, 324

Blockchain class 46-47, 57, 66, 147, 149, 206-207, 263, 267, 271, 289, 298-300, 302-303, 315

blockchain sample application 16-19

BlockchainApp 161, 164

block.difficulty property 192-193

C

calculateHash method 29, 31-32, 56-57, 82, 87-88, 95-96, 98-99, 163-164

callback hell 226

callback pattern 226

callback queue 227

chain$RevocableProxy.revoke method 218

checkIndex method 140

checkLimit method 219-220

checkTampering method 140, 180

checkTimestamp method 140

Choice 131

CJS (CommonJS) 159

class types 314-315

class-based inheritance 36-41

closures 90-100

code correctness 310

cognitive load 158

CommonJS (CJS) 159

complete method 284, 290-291

compose 82, 84-85, 94-95, 97-98, 103, 105, 110-111, 114, 116, 123-124, 129, 138, 143, 153-154, 197, 214, 244, 293

compose2 82, 85, 89, 144

composeM 143, 154

composeM2 144

composition 62, 125

computeBalance method 107, 109

compute_balance module 176

concat 199

concatenative object extension 54, 57

configurable 26, 52

constructor functions 30-36

functions as templates 30-31

sharing properties by using constructors 31-36

constructor property 126

contextual composition 123

contextual validation 131-150

choices 132-133

composing with monads 138-141

kinds of ADTs 131-132

point-free coding 144-146

reducing complex data structures 146-149

third-party integration 149-150

Validation monad 134-137, 142-143

control protocols 192-196

copy operation 6

count function 9, 84-85, 191

countBlocksInFile method 105-106, 138, 242, 249-250, 253

Counter object 218-219

countWords method 85

countWordsInFile method 84-85, 105

currency property 316-317

curry function 91, 93-95, 97-99, 104, 110-113, 143, 186, 244, 313

currying and closures 90-100

composition and 96-100

curried function application 91-95

D

data locality 231

data propagation 279

data streams 273-278

defined 274-275

implementing streamable array 275-278

dataStream 255

Date object 203

DateTime object 100

dead-code elimination 178-180

decode function 84, 92, 138

decomposing complex code 87-90

default property 173, 176, 203

DEFAULT_ALGO_SHA256 function 61

DelayedPromise class 201

delete method 19, 26

differential inheritance 6, 29-30

Difficulty object 322-323

discriminated union 132

displayTransaction method 32

done property 256, 263, 305

doSomething function 51, 53

doWork function 134

dynamic binding 150-153

dynamic importing 175-177

dynamic introspection 211-218

autohashed blocks 216-217

proxy objects 212-215

Reflect API 215-216

revocable proxies 217-218

dynamic module system 167

dynamic object extension 57

dynamic streamification 300-305

E

effectful functions 78

effects 117

enroll method 6

enumerable data descriptor 188

Enumerable interface 205

enumerable: true property 52

enumeration 322

equals method 101

equals property 316

error method 284, 293-294

Error type 248

error-first callbacks 230

ESM (ECMAScript module) 12, 157-182, 185

benefits of 178-181

dead-code elimination and tree-shaking 178-180

faster property lookups 180-181

type-friendliness 181

exporting 172-174

multivalue exporting 173

proxying 174

single-value exporting 172-173

importing 174-177

dynamic importing 175-177

multivalue importing 174-175

package managers 175

single-value importing 174

.mjs file extension 177-178

modular programming 158-160

module patterns 160-167

factory functions 165-167

IIFE mixins 164

IIFEs 163-164

object namespaces 161-163

path specifiers 171-172

static vs. dynamic module systems 167-170

EventEmitter 276

EventListener object 281

executor function 228

explicit object links 44-45

export keyword 12, 168, 170

exporting 172-174

multivalue exporting 173

proxying 174

single-value exporting 172-173

exports variable 177

_.extend 40

extracted function 110

F

factory functions 165-167

Failure 134-136, 139, 142, 148, 154, 231, 255, 268-269, 323

filter operator 286

flat method 75, 109, 122, 128-129

flatMap 10, 75, 109, 114, 116, 122-124, 127-129, 131, 134, 142-143, 148, 154, 264

fluent chaining 234-242

broken chains 236-237

fully linked chains 235

nested chains 237-242

Foo 44

foo module 179

FP (functional programming) 7, 74

F.prototype object 31

fromNullable function 139

fs library 169, 229

fs.createReadStream function 272, 275

fs.ReadStream function 275

function types 317-318

functional programming 73-113

currying and closures 90-100

composition and 96-100

curried function application 91-95

functional composition 81-90

decomposing complex code 87-90

side effects 84-87

functions as data 76-78

immutable objects 100-104

imperative programmming vs. 79-81

native function chains 111-113

point-free coding 104-106

rules of 78-79

transformation from imperative to 106-111

functional programming (FP) 7, 74

functions 7-12

as data 76-78

as templates 30-31

constructor functions 30-36

contextual validation with higher-order functions 131-150

factory functions 165-167

Functor mixin 125-126, 130, 138-139, 142, 202-203, 317

Functor.map 230, 233, 244, 279, 317

functors 10, 124-127

G

generateBlocksFromFile function 270, 272

Generator object 208, 266-267, 305

generators 266-272

async generators 269-272

creating iterable objects 267-269

representing push streams with 290-295

returning or yielding 266-267

generic types 318-321

get method 125, 212-213, 215, 219

getAddress method 6

getOwnPropertyDescriptors 215

getOwnPropertySymbols 215

global registry 189-190

H

has method 213-215

HasBread object 55

hash property 89, 145

HasHash mixin 57-58, 60, 62, 67, 69, 79, 82, 95-96, 99-100, 164, 173, 194

hashPrefix 193, 244

HashTransaction class 29-32, 38, 40, 49

HasSignature mixin 60-62

HasValidate mixin 217

HasValidation mixin 62, 134, 146, 207, 263, 272

higher-kinded composition 114-154

Array.prototype.flat 122

Array.prototype.flatMap 122-123

contextual validation 131-150

choices 132-133

composing with monads 138-141

kinds of ADTs 131-132

point-free coding 144-146

reducing complex data structures 146-149

third-party integration 149-150

Validation monad 134-137, 142-143

functors 124-127

map/compose correspondence 123-124

method extraction and dynamic binding 150-153

monads 127-131

higher-order function 76

hint parameter 203

HKT (Higher-Kinded Type) 317

homoiconic languages 186

I

Id class 120-121, 123-127, 130-131

Id#get method 126

identity function 120, 219

IIAFE (Immediately Invoked Async Function Expression) 257

IIFEs (Immediately Invoked Function Expressions) 163-164

immutable objects 100-104

imperative programmming

functional programming vs. 79-81

transformation to functional programming 106-111

implicit object links 43-44

import function 176

import keyword 12, 168, 170, 176

importing 174-177

multivalue import 174-175

package managers 175

single-value import 174

in operator 214

index property 216

indexOf method 276

inheritance 23

inheritance-based object modeling 23-41

class-based inheritance 36-41

constructor functions 30-36

functions as templates 30-31

sharing properties by using constructors and prototypes 31-36

prototypal inheritance 24-30

differential inheritance 29-30

property resolution process 27-29

init method 46-47, 50

inspect method 196

interface types 315-316

invariant 312

IObservable class 320-321

@@isConcatSpreadable 199-200

isFunction 92

ISubscription class 320

isValid method 75, 141, 143, 146, 148

iterables and iterators 262-266

examples of 263-266

iterable protocol 262

iterator protocol 263

@@iterator 205-210

Iterator object 252, 263

J

JavaScript 1-20

blockchain sample application 16-19

code 12

data 13-16

evolution of 4-5

functions 7-12

objects 5-7

types for 308-324

benefits and drawbacks of 310-314

type annotations 314-324

jQuery object 127

JSON.parse method 105

JSON.stringify method 29, 96, 197

L

lazy evaluation 83

ledger 106, 110, 173

ledger.validate method 218

left property 209

left.getOrElse(5) method 269

lenses 103

linear async flows 225-259

architecture 226-228

async/await feature 249-252

async iteration 252-257

top-level await 257-259

promise combinators 244-249

Promise.all 246-247

Promise.allSettled 247-248

Promise.any 248-249

Promise.race 247

promises 228-244

data locality 231

fluent chaining 234-242

not algebraic 231-234

real-world examples 242-244

linearization 63-65

linked, compositional object models 42-70

mixins 54-66

applying shared mixins to multiple objects 66-70

composing objects using Object.assign and spread operator 65-66

multiple inheritance and linearization 63-65

object links 43-45

explicit 44-45

implicit 43-44

Object.assign API 50-54

assignment vs. definition 53-54

using 51-53

OLOO pattern 45-50

live code bindings 169

local registry 188-189

M

map interface 123-124

Map object 262

map operator 283-286

map/flatMap 13

metaprogramming 183-222

common uses of 184-186

dynamic introspection and weaving 211-218

autohashed blocks 216-217

proxy objects 212-215

Reflect API 215-216

revocable proxies 217-218

method decorators 218-220

symbols 186-188

practical application of 190-197

symbol registries 188-190

well-known 198-210

method decorators 218-220

method extraction 150-153

method fusion 129

mineNewBlockIntoChain method 194

minus method 103

minus property 316

mixins 43, 54-66

applying shared mixins to multiple objects 66-70

composing objects using Object.assign and spread operator 65-66

multiple inheritance and linearization 63-65

.mjs file extension 177-178

modular programming 158-160

module patterns 160-167

factory functions 165-167

IIFE mixins 164

IIFEs 163-164

object namespaces 161-163

static vs. dynamic module systems 167-170

module variable 177

Monad mixin 128, 130-131, 142

Monad.flatMap 233, 244, 279

monads 127-131

composing with 138-141

point-free coding with 144-146

Validation monad 134-137, 142-143

monomorphic functions 313

multivalue exporting 173

multivalue importing 174-175

N

native function chains 111-113

nested chains 237-242

new keyword 5, 31, 33-36, 120, 165, 187

newBlock method 267-268

next method 209, 263, 265-266, 269, 275, 278, 283-284, 286, 290-291, 305

next(value) method 277-278

nominal typing 314

nonce property 194-195, 216, 244

NoopFunctor mixin 139

NoopMonad mixin 142

NPM 175

null value 115, 117-118, 133-134, 313

Number object wrapper 310

O

obj :: method 152

obj parameter 65, 95, 188

object links 43-45

explicit 44-45

implicit 43-44

object namespaces 161-163

object types 316-317

Object#hasOwnProperty method 52

Object#isPrototypeOf method 28, 103

Object#toString method 203

Object#valueOf method 203

Object.assign API 50-54

assignment vs. definition 53-54

composing objects using spread operator and 65-66

using 51-53

Object.assign method 6, 26, 42, 50-55, 58-60, 63-65, 70, 102, 188, 289, 302

Object.create method 5, 25-27, 32, 42, 45, 50, 100

Object.create(Blockchain) method 46

Object.create(null) method 102

Object.create(Transaction.prototype) method 192

Object.defineProperty method 53, 188, 215

Object.freeze method 102-103

Object.fromEntries method 99

Object.getOwnPropertyDescriptors method 185

Object.getOwnPropertyNames method 185, 187

Object.getOwnPropertySymbols API 191

Object.getOwnPropertySymbols method 185, 187

Object.getPrototypeOf method 28, 185

Object.keys method 26

Object.prototype method 27, 103

objects 5-7

immutable 100-104

inheritance-based object modeling 23-41

linked, compositional object models 42-70

streamifying 297-300

Objects Linked to Other Objects (OLOO) 42, 45-50

Object.seal method 102-103

Object.setPrototypeOf method 28, 30

obj.toArray() 147

@@observable 297

Observable API 278-305

dynamic streamification 300-305

observable mixin extension 288-290

observables

creating custom 281-282

defined 279-281

pipeable operators 295-297

reactive toolkit 282-288

filter operator 286

map operator 283-286

reduce operator 286

skip operator 287-288

representing push streams with generators 290-295

streamifying objects 297-300

Observable function 15, 153, 260, 262, 274, 278, 280-284, 288, 290, 293, 297, 302, 304-305, 320-321

Observable.{of, from} function 281

Observable.from function 279, 297

Observable.fromGenerator function 291

Observable.of function 280, 283

Observable.of(...) function 297

Observable.prototype function 283

observables 5

Observer object 278, 280-281, 293, 320

observer.complete method 298

OLOO (Objects Linked to Other Objects) 42, 45-50

on method 276

onlyIf function 78

optionally (pluggable) typed 310

orElse function 78

P

Pair object 132, 200, 209, 297

parameterized type 318

parent property 52

path specifiers 171-172

pipe operator 111-112, 197, 288

pipeable operators 295-297

pipeline operator 5

Point object 100

point-free coding 104-106, 144-146

polymorphic types 313, 317

precomputedHash operator 133

preserves type 81

previousHash property 17, 145, 216, 246

private class fields 5

process.hrtime API 217-218

programmable commas 146

Promise API 153, 225-226, 228, 250, 257, 259, 261, 304

promise combinators 244-249

Promise.all 246-247

Promise.allSettled 247-248

Promise.any 248-249

Promise.race 247

Promise object 13, 15, 131, 231-232, 234, 236, 238, 240, 247, 249-251, 253, 255, 266, 269, 275, 305

Promise#catch 234, 237-240, 248, 250, 255, 257

Promise#finally 241

Promise#then 229, 233-234, 238, 244, 248-250, 255, 257

Promise.all 246-248

Promise.allSettled 247-248, 259

Promise.any 247-249, 259

Promise.race 247-248

promises 228-244

data locality 231

fluent chaining 234-242

broken chains 236-237

fully linked chains 235

nested chains 237-242

not algebraic 231-234

real-world examples 242-244

proof of work 18

proofOfWork function 18, 193-194, 245, 311, 322

proofOfWorkAsync function 245

prop function 92, 94-95, 98, 185

prop('funds') function 93

properties

assignment vs. definition 53-54

ESMs and faster lookups 180-181

resolution process 27-29

sharing by using constructors and prototypes 31-36

props function 94, 99, 185

proto object 25

__proto__ property 27-28, 33-34, 41, 43, 45

prototypal inheritance 24-30

differential inheritance 29-30

property resolution process 27-29

sharing properties by using prototypes 31-36

prototype pollution 6

prototype property 32-34, 40, 47, 65, 192

prototype, inheritance vs. 23

Proxy API 211, 304

Proxy object 12, 184, 212, 215, 218

proxy objects 212-215

proxying 174

pure functions 8, 76, 78

push generator 278

push method 300

pushProxy 300

pyramid of doom 226

Q

Queue 131

R

reacting 276

ReactiveExtensions mixin 288

read function 84, 138

Readable 291

readFile method 230

realms 190

Record type 131-132

reduce API 75, 89, 264

reduce function 110, 144, 148

reduce operator 286

reduceRight operator 111

ReferenceError class 313

referential transparency 78

Reflect API 12, 184, 211, 215-216, 304

Reflect.ownKeys API 191

require API 180

require function 168, 176

return method 178, 290

reverse API 121

reverse method 76

revocable proxies 217-218

revoke method 218

right property 209

right-biased 139

S

SafeIncrementor 152

safeSquare 78

serialization 196-197

set method 215

Set object 262

setInterval method 280

setTimeout method 228

shortcut fusion 129

side effects 84-87

single-value exporting 172-173

single-value importing 174

skip operator 287-288, 292, 297

sort API 121

sort method 76

@@species 200-203

documenting closure of operations 202-203

information hiding 201-202

split function 9, 84-85, 105

spread operator 65-66

square function 78, 302

static method 40

status property 248

Stream APIs 14

stream.Readable 275, 291

streams programming 260-305

data streams 273-278

defined 274-275

implementing streamable array 275-278

generators 266-272

async generators 269-272

creating iterable objects 267-269

returning or yielding 266-267

streams programming (continued)

iterables and iterators 262-266

examples of 263-266

iterable protocol 262

iterator protocol 263

Observable API 278-305

creating custom observables 281-282

dynamic streamification 300-305

observable mixin extension 288-290

observables, defined 279-281

pipeable operators 295-297

reactive toolkit 282-288

representing push streams with generators 290-295

streamifying objects 297-300

String object wrapper 310

subscribe method 276-277, 280, 282-283, 290

Subscription object 275, 280-281

Success 134-136, 138-139, 142-143, 148, 154, 231, 268, 317, 323

Success.of 255

sum type 132

switch statements 133, 322

Symbol API 187

Symbol function 181, 187-189, 198, 221

symbol registries

global registry 189-190

local registry 188-189

Symbol('foo') property 188

Symbol('name') property 192

Symbol.asyncIterator function 255-256, 276, 297, 305

Symbol.for function 188-189

Symbol.for('toJson') function 197

Symbol.for('version') function 197

Symbol.for(key) function 190

Symbol.isConcatSpreadable function 200

Symbol.iterator function 147, 206, 262-265, 267-268, 276, 297, 305

Symbol.keyFor(key) function 190

Symbol.observable method 279, 297, 302, 305

symbols 186-188

practical application of 190-197

hidden properties 190-191

interoperability 191-196

serialization 196-197

symbol registries 188-190

well-known 198-210

@@isConcatSpreadable 199-200

@@iterator 205-210

@@species 200-203

@@toPrimitive 203-205

@@toStringTag 198-199

Symbol.species method 200

Symbol.toPrimitive method 203

Symbol.toStringTag method 198

symFoo 188

SyntaxError class 39

T

then method 288

this 31, 34, 70, 88, 96, 99, 107, 151, 164-166, 241, 262, 296-297

this.calculateHash 216

this.constructor.of 126

throw expressions 5, 183, 193, 219

timestamp property 216

toJson method 196-197

@@toPrimitive 203-205

toString method 92, 101, 192, 198-199, 203

toString property 103, 316

@@toStringTag 198-199

toStringTag method 199

toUpperCase() method 319

traceLogHandler 216

Transaction class 27, 31, 36-37, 40, 47, 54, 57-59, 62, 65-66, 100-101, 149, 161, 163-164, 168, 173, 192, 207

Transaction object 26, 48, 263, 315

transaction object 29

transactionId value 29, 101

Transaction.prototype 32

transferFunds 166

tree-shaking 178-180

try/catch 116

type-friendliness of ESMs 181

typeclass 130

TypeError 27, 32, 313

U

union types 322-324

unsubscribe method 277, 280, 282, 284, 298

UpperCaseFormatter 44

url property 178

use method 57

util library 35

util.inherits method 35, 40

util.promisify method 230

V

validate API 146

validate function 148, 208, 216-217, 219, 272

Validation 134-135, 137, 139, 141-144, 146, 148-149, 153, 168, 202, 204, 230, 232, 255, 268, 283, 293, 318

Validation monad 134-143

Validation#map 202

Validation.Failure 148

Validation.map 255

Validation.of 283

validationResult 148

Validation.Success 148, 317

validBlocks$ 293

value property 248, 263, 305

valueOf method 101, 103, 203

values method 207

version property 195

W

WeakMap 262

WeakSet 262

weaving 211-218

autohashed blocks 216-217

proxy objects 212-215

Reflect API 215-216

revocable proxies 217-218

window object 57

WindowEventHandlers mixin 57

WindowOrWorkerGlobalScope mixin 57

with statement 19

workers 227

worker_threads module 245

writable attribute 52

Y

yield 209, 267, 290