-
Notifications
You must be signed in to change notification settings - Fork 4
Fluent Interface
For data pipelines, invoking serial methods can become verbose.
data = compute.roundn( data, -3 );
data = compute.mean( data );
data = compute.roundn( data, 0 );
...
Fluent interfaces can help alleviate this problem. Such interfaces have been popularized by libraries such as jQuery and D3 which utilize method chaining.
To create a fluent interface,
var flow = compute.flow();
A flow
pipeline should be initialized.
flow.value( data );
Once initialized, all compute methods are now available. The lone difference is that data should not be explicitly passed as an argument. For example,
flow
.value( data )
.roundn( -3 )
.mean()
.roundn( 0 );
To return the flow value
,
var mean = flow.value();
To help understand the transformations comprising a data pipeline, flow
exposes an inspect()
method, which logs the current value
to the console while maintaining the fluent interface.
flow.inspect();
The above flow
can be modified accordingly,
flow
.value( data )
.inspect()
.roundn( -3 )
.inspect()
.mean()
.inspect()
.roundn( 0 )
.inspect();
To summarize the flow
API...
This method is a setter/getter. If no value
is provided, returns the current flow value
. If a value
is provided, sets the flow value
.
flow.value( [ 4, 3, 6, 2 ] );
Logs the current flow value
to the console, while maintaining the fluent interface.
flow.inspect();
- When creating flows, ensure that the output from one computation matches the input argument requirements for the next computation.
- For large datasets, rather than loading datasets into memory, consider using file streams and utilize stream tools such as Flow.io.
- Utilities
- Array Creation
- Sorting and Reshaping Arrays
- Special Functions
- Arithmetic
- Relational Operations
- Logical Operations
- Trigonometry
- Geometry
- Sets
- Discrete Mathematics
- Linear Algebra
- Statistics