Add fluent API
See original GitHub issueOften it’s really annoying to rewrite long chained operations in an functional style. The https://github.com/mindeavor/es-pipeline-operator would help with this when it arrives, but for now, expressions like flyd .on (..., filter (..., filter (..., target_range)) .map (...))
are absolutely unreadable, especially with complex functions in between. I switched from most.js, and their style of target_range .filter (...) .filter (...) .map (...) .observe (...)
is much more pleasing and easier to use. I propose to add the following line to amend this problem.
function createStream() {
function s(n) {
if (arguments.length === 0) return s.val
updateStreamValue(s, n)
return s
}
s.hasVal = false;
s.val = undefined;
s.vals = [];
s.listeners = [];
s.queued = false;
s.end = undefined;
s.map = boundMap;
/*fluent api*/s.thru = function (thru) { return thru (s); };
s.ap = ap;
s.of = flyd.stream;
s.toString = streamToString;
return s;
}
or perhaps
function createStream() {
function s(n) {
if (arguments.length === 0) return s.val
updateStreamValue(s, n)
return s
}
s.hasVal = false;
s.val = undefined;
s.vals = [];
s.listeners = [];
s.queued = false;
s.end = undefined;
s.map = boundMap;
/*fluent api 2*/s.thru = function (func, args) { return func .apply (s, [] .concat .call (args || [], [s])); };
s.ap = ap;
s.of = flyd.stream;
s.toString = streamToString;
return s;
}
Which would also allow usages like stream.thru(filter,[isOdd]).map(square).thru(flyd.transduce, R.take(5))
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:14 (9 by maintainers)
Top Results From Across the Web
Fluent API in Entity Framework Core
Configurations Fluent API Methods Usage
Model Configurations HasDefaultSchema() Specifies the database schema.
Entity Configuration HasIndex() Configures an index of the specified properties.
Read more >Fluent API - Configuring and Mapping Properties and Types
This article is designed to demonstrate how to use the fluent API to configure properties. The code first fluent API is most commonly...
Read more >Fluent API Configuration - Learn Entity Framework Core
EF Core's Fluent API provides methods for configuring various aspects of your model: ... Configurations are applied via a number of methods exposed...
Read more >Entity Framework - Fluent API - Tutorialspoint
Fluent API is an advanced way of specifying model configuration that covers everything that data annotations can do in addition to some more...
Read more >Using Fluent API in Entity Framework Core Code First
Fluent API is used to configure data models to override conventions. It is based on the Fluent API design pattern where results are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I second with @StreetStrider to use Ramda.pipe (equivalent to _.flow) and currying in this situation. flyd already has a data/stream in last position API.
The code layout becomes nearly same as with fluent apis, but gets the additional benefit of being more declarative without introducing a feature coming from an OOP style.
When I wrote Flyd I was very much against methods. But these days I definitely think that fluent APIs do have their benefits.
I think the biggest issue is that Flyd tries to be modular. But, with a fluent API all methods will have to be available at the prototype.
I think @squiddle’s suggestion of using
R.pipe
is nice. It sorta achieves the same thing as the pipeline operator.@StreetStrider
That sounds very interesting! Definitely share it if you find it.