Home Manual Reference Source

Overview

Installation

Can be managed using jspm or npm.

jspm

jspm install npm:@functional-data-structure/persistent

npm

npm install @functional-data-structure/persistent --save

Usage

The code needs a ES2015+ polyfill to work, for example regenerator-runtime/runtime.

await import( 'regenerator-runtime/runtime.js' ) ;
// or
import 'regenerator-runtime/runtime.js' ;

Then

const persistent = await import( '@functional-data-structure/persistent' ) ;
// or
import persistent from '@functional-data-structure/persistent' ;

Examples

import { Measures } from '@functional-abstraction/measure' ;
import { empty } from '@functional-data-structure/finger-tree' ;
import persistent from '@functional-data-structure/persistent' ;

let Seq = persistent.seq( empty , Measures.LEN ) ;
let Heap = persistent.heap( empty , Measures.MAX ) ;
let OrdSeq = persistent.ordseq( empty , Measures.KEY ) ;
let IndOrdSeq = persistent.indordseq( empty , Measures.KEY , Measures.LEN , Measures.KEY_LEN ) ;
let IntervalTree = persistent.intervaltree( empty , Measures.INTERVAL ) ;

let seq = Seq.from( 'abc' ) ;
seq.get( 1 ) ; // 'b'

let heap = Heap.from( [ 1 , 3 , 2 ] ) ;
heap.extractMax( ) ; // [ 3 , Heap{1,2} ]

let ordseq = OrdSeq.from( 'abracadabra' ) ;
[ ...ordseq ] ; // aaaaabbcdrr

let indordseq = IndOrdSeq.from( 'abracadabra' ) ;
[ ...indordseq ] ; // aaaaabbcdrr
indordseq.get( 7 ) ; // 'c'

let intervaltree = IntervalTree.from( [ [ 1 , 5 ] , [ 4 , 9 ] ] ) ;
intervaltree.intervalSearch( [ -7 , 3 ] ) ; // [ 1 , 5 ]
intervaltree.intervalSearch( [ 7 , 12 ] ) ; // [ 4 , 9 ]
intervaltree.intervalSearch( [ 11 , 12 ] ) ; // null