@@ -23,11 +23,12 @@ import { isPromise, isAsyncIterable } from './util/compat';
23
23
import { Vector , DictionaryVector , IntVector , StructVector } from './vector' ;
24
24
import { ChunkedView } from './vector/chunked' ;
25
25
26
- export type NextFunc = ( idx : number , cols : RecordBatch ) => void ;
26
+ export type NextFunc = ( idx : number , batch : RecordBatch ) => void ;
27
+ export type BindFunc = ( batch : RecordBatch ) => void ;
27
28
28
29
export interface DataFrame {
29
30
filter ( predicate : Predicate ) : DataFrame ;
30
- scan ( next : NextFunc ) : void ;
31
+ scan ( next : NextFunc , bind ?: BindFunc ) : void ;
31
32
count ( ) : number ;
32
33
countBy ( col : ( Col | string ) ) : CountByResult ;
33
34
}
@@ -128,11 +129,12 @@ export class Table implements DataFrame {
128
129
public filter ( predicate : Predicate ) : DataFrame {
129
130
return new FilteredDataFrame ( this . batches , predicate ) ;
130
131
}
131
- public scan ( next : NextFunc ) {
132
+ public scan ( next : NextFunc , bind ?: BindFunc ) {
132
133
const batches = this . batches , numBatches = batches . length ;
133
134
for ( let batchIndex = - 1 ; ++ batchIndex < numBatches ; ) {
134
135
// load batches
135
136
const batch = batches [ batchIndex ] ;
137
+ if ( bind ) { bind ( batch ) ; }
136
138
// yield all indices
137
139
for ( let index = - 1 , numRows = batch . length ; ++ index < numRows ; ) {
138
140
next ( index , batch ) ;
@@ -189,7 +191,7 @@ class FilteredDataFrame implements DataFrame {
189
191
this . batches = batches ;
190
192
this . predicate = predicate ;
191
193
}
192
- public scan ( next : NextFunc ) {
194
+ public scan ( next : NextFunc , bind ?: BindFunc ) {
193
195
// inlined version of this:
194
196
// this.parent.scan((idx, columns) => {
195
197
// if (this.predicate(idx, columns)) next(idx, columns);
@@ -199,6 +201,7 @@ class FilteredDataFrame implements DataFrame {
199
201
for ( let batchIndex = - 1 ; ++ batchIndex < numBatches ; ) {
200
202
// load batches
201
203
const batch = batches [ batchIndex ] ;
204
+ if ( bind ) { bind ( batch ) ; }
202
205
const predicate = this . predicate . bind ( batch ) ;
203
206
// yield all indices
204
207
for ( let index = - 1 , numRows = batch . length ; ++ index < numRows ; ) {
0 commit comments