Skip to content

Instantly share code, notes, and snippets.

@darrensapalo
Created June 2, 2020 09:14
Show Gist options
  • Save darrensapalo/01b4484eef58b1581383677c652a049f to your computer and use it in GitHub Desktop.
Save darrensapalo/01b4484eef58b1581383677c652a049f to your computer and use it in GitHub Desktop.
Discussions with Baron regarding dynamic processing
import { OperatorFunction, pipe, from } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import axios from 'axios';
interface Operation {
// config yml
type: 'map'|'filter';
};
const operations: Operation[] = [];
const rxOperatorFunctions = operations.map(buildRxOperator);
// [operator1, operator2, operator3]
// reduce =>
// OperatorFunction<any, any>[]
// OperatorFunction<any, any>
const combinedOperation = rxOperatorFunctions.reduce((acc, curr) => {
return pipe(acc, curr)
}, tap());
// First run - acc = tap()
// Second run - acc = tap() curr = operator1 ...... acc = pipe(tap(), operator1)
// Third run - acc = pipe(tap(), operator1) curr = operator2 ..... acc = pipe(pipe(tap(), operator1), operator2) === pipe(tap(), operator1, operator2)
// SUM
[1,2,3,4,5,6].reduce((acc, curr) => acc + curr, 0);
// First run - acc=0
// Second run - acc=0 curr=1 ...... acc = acc + curr = 1
// Third run - acc=1 curr=2 ..... acc = acc + curr = 3
// Fourth run - acc=3 curr
from([1, 2, 3, 4, 5]).pipe(
combinedOperation
);
function buildRxOperator(operation: Operation): OperatorFunction<any, any> {
switch(operation.type) {
case 'map':
return mapSomething();
case 'filter':
return buildFilter(operation);
case 'write_to_csv':
return writeToCsv();
}
}
export interface CsvRow {
a: string;
b: string;
}
function mapSomething() {
return map<CsvRow, CsvRow>((data: CsvRow) => {
return {} as CsvRow;
});
}
// select only a subset of the columns
function filterColumns() {
return map<CsvRow, CsvRow>((data: CsvRow) => {
return {
a : null,
b: '5'
} as CsvRow;
});
}
function buildFilter(operation) {
if (true || operation.type === 'GREATER_THAN') {
return filter()
} else {
}
}
function writeToCsv() {
return pipe(toArray(), mergeMap(rows => {
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment