Skip to content

Commit

Permalink
delay/Lazy fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Sep 7, 2015
1 parent 7d19147 commit f0ca581
Show file tree
Hide file tree
Showing 37 changed files with 248 additions and 62 deletions.
216 changes: 168 additions & 48 deletions js/dist/fingertree.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/fingertree.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/fingertree.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const app3 = function ( A , list , B ) {

A = A.force( ) ;
B = B.force( ) ;

if ( A instanceof Empty ) return extendleft( B , list ) ;
if ( B instanceof Empty ) return extend( A , list ) ;

Expand All @@ -9,11 +12,11 @@ const app3 = function ( A , list , B ) {
return new Deep(
A.measure ,
A.left ,
app3(
delay( ( ) => app3(
A.middle ,
nodes( A.measure , [ ...chain( A.right , list , B.left ) ] ) ,
B.middle
) ,
) ) ,
B.right
) ;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function deepL ( M , left , middle , right ) {

if ( middle.empty( ) ) return from_iterable( M , right ) ;

return new Deep( M , middle.head( ).digit( ) , middle.tail( ) , right ) ;
return new Deep( M , middle.head( ).digit( ) , delay( ( ) => middle.tail( ) ) , right ) ;
}

return new Deep( M , digit( left ) , middle , right ) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function deepR ( M , left , middle , right ) {

if ( middle.empty( ) ) return from_iterable( M , left ) ;

return new Deep( M , left , middle.init( ) , middle.last( ).digit( ) ) ;
return new Deep( M , left , delay( ( ) => middle.init( ) ) , middle.last( ).digit( ) ) ;
}

return new Deep( M , left , middle , digit( right ) ) ;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions js/src/tree/0-sugar/Tree.js → js/src/3-tree/0-sugar/Tree.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

class Tree {

force ( ) {
return this ;
}

takeUntil ( p ) {
return this.split( p )[0] ;
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Deep extends Tree {
return from_iterable( this.measure , this.right ) ;
}

return new Deep( this.measure , this.middle.head( ).digit( ) , this.middle.tail( ) , this.right ) ;
return new Deep( this.measure , this.middle.head( ).digit( ) , delay( ( ) => this.middle.tail( ) ) , this.right ) ;

}

Expand All @@ -48,7 +48,7 @@ class Deep extends Tree {
return from_iterable( this.measure , this.left ) ;
}

return new Deep( this.measure , this.left , this.middle.init( ) , this.middle.last( ).digit( ) ) ;
return new Deep( this.measure , this.left , delay( ( ) => this.middle.init( ) ) , this.middle.last( ).digit( ) ) ;

}

Expand Down
File renamed without changes.
62 changes: 62 additions & 0 deletions js/src/4-lazy/Lazy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class Lazy extends Tree {

constructor ( thunk ) {
super( ) ;
this.tree = null ;
this.thunk = thunk ;
}

force ( ) {
if ( this.tree === null ) this.tree = this.thunk( ) ;
return this.tree ;
}

empty ( ) {
return this.force( ).empty( ) ;
}

get v ( ) {
return this.force( ).v ;
}

head ( ) {
return this.force( ).head( ) ;
}

last ( ) {
return this.force( ).last( ) ;
}

unshift ( value ) {
return this.force( ).unshift( value ) ;
}

push ( value ) {
return this.force( ).push( value ) ;
}

tail ( ) {
return this.force( ).tail( ) ;
}

init ( ) {
return this.force( ).init( ) ;
}

splitTree ( p , i ) {
return this.force( ).splitTree( p , i ) ;
}

split ( p ) {
return this.force( ).split( p ) ;
}

concat ( other ) {
return this.force( ).concat( other ) ;
}

* [Symbol.iterator] ( ) {
yield* this.force( ) ;
}

}
3 changes: 3 additions & 0 deletions js/src/4-lazy/delay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function delay ( thunk ) {
return new Lazy( thunk ) ;
}
6 changes: 0 additions & 6 deletions js/src/tree/1-base/3-Lazy.js

This file was deleted.

0 comments on commit f0ca581

Please sign in to comment.