Skip to content

Commit 84c92da

Browse files
committed
Update lazy box
1 parent 9c641e2 commit 84c92da

File tree

1 file changed

+6
-43
lines changed

1 file changed

+6
-43
lines changed

examples/11-lazy-box.js

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ const LazyBox = g => ({
1111
// compose with f from outside
1212
map: f => LazyBox( _ => f(g()) ),
1313

14-
// compose and evaluate
14+
// compose and evaluate only here!
1515
fold: f => f(g())
1616
})
1717

1818

1919
const nextCharForNumberString = str =>
2020

2121
// wrap 'str' first into function call
22-
LazyBox( () => str )
22+
LazyBox( _ => str )
2323

2424
// every 'map' composes with new function from outside
2525
// without calling it
@@ -31,45 +31,8 @@ const nextCharForNumberString = str =>
3131
// compose again and call the function
3232
.fold(s => s.toLowerCase())
3333

34-
console.log(nextCharForNumberString(' 64 '))
35-
36-
37-
// ==== Experiment
38-
39-
// The bove LazyBox needs a function and ignores its arguments.
40-
// It must be called every time as LazyBox( () => val ),
41-
// which may not be convenient to consume
42-
// It may be more convenient to pass the actual value:
43-
44-
45-
// TODO === not finished yet
46-
47-
const LazyWrapper = x => ({
48-
49-
wrapper: () => x,
50-
51-
// compose with f from outside
52-
map: f => LazyWrapper( f(x) ),
53-
54-
// compose and evaluate
55-
fold: f => f(x)
56-
})
57-
58-
const nextCharForNumberString1 = str =>
59-
60-
// wrap 'str' first into function call
61-
LazyWrapper( str )
62-
63-
// every 'map' composes with new function from outside
64-
// without calling it
65-
.map(s => s.trim())
66-
.map(r => parseInt(r))
67-
.map(i => i + 1)
68-
.map(i => String.fromCharCode(i))
69-
70-
// compose again and call the function
71-
.fold(s => s.toLowerCase())
72-
73-
console.log(nextCharForNumberString1(' 64 '))
74-
34+
console.log(
35+
"nextCharForNumberString(' 64 '): ",
36+
nextCharForNumberString(' 64 ')
37+
)
7538

0 commit comments

Comments
 (0)