@@ -38,7 +38,6 @@ <h2>Simple SVG Graphics: Stairs</h2>
3838 import { Sequence } from "../../kolibri/sequence/constructors/sequence/Sequence.js" ;
3939 import { dom } from "../../kolibri/util/dom.js" ;
4040 import { Seq } from "../../kolibri/sequence/constructors/seq/seq.js" ;
41- import { id } from "../../kolibri/stdlib.js" ;
4241
4342 const svgWidth = 500 ;
4443 const [ svg ] = dom ( `<svg id="svg" viewBox="${ - svgWidth / 2 } ${ - svgWidth / 2 } ${ svgWidth } ${ svgWidth } " > </svg> ` ) ;
@@ -65,18 +64,17 @@ <h2>Simple SVG Graphics: Stairs</h2>
6564 const allTrails = Sequence ( trail , forever , nextAfter ) ; // pure, lazy
6665 const renderLine = line => svg . innerHTML += line ; // impure side effect
6766 const waitThenOk = ms => ok => setTimeout ( ok , ms ) ; // impure async
68- const callThenOk = f => ok => { f ( ) ; ok ( ) } ; // ready for promise ctor
67+ const callThenOk = f => ok => ok ( f ( ) ) ; // ready for promise ctor
6968
7069 const lazyLines = allTrails
7170 . map ( lineFor )
7271 . map ( line => ( ) => renderLine ( line ) ) // map to a sequence of _functions_ that can be called as f()
7372 . map ( callThenOk ) // make each function Promise-ready
7473 . and ( f => Seq ( f , waitThenOk ( 50 ) ) ) // intersperse monadically FTW
75- . scan ( ( acc , cur ) => acc . then ( ( ) => new Promise ( cur ) ) , Promise . resolve ( undefined ) ) ; // fixes sequence
76-
74+ ;
7775 lazyLines
78- . take ( 255 * 2 ) // late "pruning" thanks to laziness
79- . reduce$ ( id , undefined ) ; // start the promises, trigger the painting
76+ . take ( 255 * 2 ) // late "pruning" thanks to laziness
77+ . reduce$ ( ( acc , cur ) => acc . then ( ( ) => new Promise ( cur ) ) , Promise . resolve ( undefined ) ) ;
8078
8179
8280</ script >
0 commit comments