Skip to content

Commit

Permalink
#88: TS: flatMap and lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-zozol committed Nov 5, 2017
1 parent bad6707 commit f66958c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion integration-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.js
#!/examples/beginner/chars.ts
!/examples/**.ts
!/examples/**/*.ts
2 changes: 2 additions & 0 deletions integration-ts/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import './beginner/floor'
import './beginner/hello-something'
import './beginner/number'
import './beginner/response'
import './flow/try-with-no-or'
import './lazy/transmission'



36 changes: 36 additions & 0 deletions integration-ts/examples/lazy/transmission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {Streams, F, C, Option, N, SingleParser, parserBuilder, ListParser} from '@robusta/trash'
import {assertTrue} from '../../assert';


/**
* A gives its VALUE to B using flatMap
*/
function A(char){
return C.char(char.toUpperCase()).rep().flatMap(B);
}


/**
* There is recursion, and we call A with lazy. We send PARAMETERS to A
* within an array
*/
function B(aVal) {
console.log('>>>>',aVal);
return C.char('B').map(bVal=> aVal.join('')+'-'+bVal).or(F.lazy(A, ['a']));
}



const parser = A('a');

const str = 'AAAB';
const stream = Streams.ofString(str);
const parsing = parser.parse(stream);

assertTrue(parsing.offset === str.length);

//F.startsWith()
//F.dropTo()
//F.moveUntil()
// rename F.nop() to F.nop
// parsing.isCompleted()

0 comments on commit f66958c

Please sign in to comment.