question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Often 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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
squiddlecommented, Feb 23, 2017

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.

const flydFilter = require('paldepind/flyd-filter');

R.pipe(
  flydFilter(isOdd), 
  flyd.map(square), 
  flyd.transduce(R.take(5))
)(stream);
3reactions
paldepindcommented, Mar 6, 2017

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

There was a package that allows to turn any fp-interface to fluent, but I can’t find it in my stars, nor in @paldepind stars. There was a mention of it somewhere, but I can’t find id, so sad. It takes and object of functions (data-last functions) which would create fluent interface and returns wrapper object which contains all context with context-bounded version of functions. This may be a possible solution for you.

That sounds very interesting! Definitely share it if you find it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found