These are chat archives for ramda/ramda

25th
Jun 2015
David Chambers
@davidchambers
Jun 25 2015 00:10
The low-tech solution is to keep the docs open in a browser tab. :)
Scott Sauyet
@CrossEye
Jun 25 2015 00:58

I think our docs are too big to fit in any reasonable way in ReadMe. But @raine's solution is not bad. When you grab Ramda either with npm install or git clone you could run that little bit and have a local copy of the docs.

However I have no issue with any other technique to make these easily available.

Asaf
@asaf-romano
Jun 25 2015 07:13
@CrossEye sorry if my comment was harsh in any way, the joke was funny actually :)
Raine Virta
@raine
Jun 25 2015 07:37
there's actually even easier way to save a local copy of the docs, just "save page" with browser
Asaf
@asaf-romano
Jun 25 2015 07:49
are the actually ramda docs for Dash?
Raine Virta
@raine
Jun 25 2015 07:50
think so
Asaf
@asaf-romano
Jun 25 2015 07:52
didn't find there
Tobias Pflug
@gilligan
Jun 25 2015 07:55
hi guys
anyone got a suggestion for how best to write something like waitFor(f, args, predF, retries) where f returns a Promise and waitFor repeats retries times or until predF retruns true for the result of f ?
Asaf
@asaf-romano
Jun 25 2015 07:58
found it, but it's for 0.13
Scott Christopher
@scott-christopher
Jun 25 2015 08:01
@gilligan Are they A+ Promises, or a Fantasy Land implementation?
and I’m guessing args is to be applied to f to produce the Promise?
Tobias Pflug
@gilligan
Jun 25 2015 08:05
@scott-christopher : sorry, yep indeed.. f(args) - at the moment just bloody A+ promises
Scott Christopher
@scott-christopher
Jun 25 2015 08:06
If they were FL, something like the following might work:
var waitFor = (f, args, predF, retries) => {
  if (retries > 0) {
    return f.apply(null, args).chain(fResult =>
        predF(fResult) ? Promise.of(fResult)
                       : waitFor(f, args, predF, retries - 1)
    )
  } else {
    return Promise.reject('retries exhausted');
  }
}
For A+, I think that translates to:
var waitFor = (f, args, predF, retries) => {
  if (retries > 0) {
    return f.apply(null, args).then(fResult =>
        predF(fResult) ? Promise.resolve(fResult)
                       : waitFor(f, args, predF, retries - 1)
    )
  } else {
    return Promise.reject('retries exhausted');
  }
}
Tobias Pflug
@gilligan
Jun 25 2015 08:08
@scott-christopher which fantasy-land spec fulfilling promise libs are there anyway ?
Scott Christopher
@scott-christopher
Jun 25 2015 08:08
Promise.resolve(fResult) could probably just be fResult when using A+ too.
ramda-fantasy has Future
Tobias Pflug
@gilligan
Jun 25 2015 08:08
ah yes of course
Scott Christopher
@scott-christopher
Jun 25 2015 08:09
which is essentially the same thing, with deferred execution
Tobias Pflug
@gilligan
Jun 25 2015 08:09
right
@scott-christopher thanks
Scott Christopher
@scott-christopher
Jun 25 2015 08:09
no worries
Tobias Pflug
@gilligan
Jun 25 2015 08:11
@scott-christopher i thought about something like running R.composeP on a list of wrapped f(args) functions, where the wrapping just rejects right away if retries has reached 0
but well there would have to be some more wrapping going on for composition to make sense
if that makes any sense
Scott Christopher
@scott-christopher
Jun 25 2015 08:28
Makes sense
Another hacky alternative would be to use the short-circuiting behaviour of Promise.reject to carry the successful case.
Then you could chain a series of N promises, ending with a Promise.resolve("exhausted").
Scott Christopher
@scott-christopher
Jun 25 2015 08:33
But I probably wouldn't be too happy to stumble across that in a code base :smile:
Tobias Pflug
@gilligan
Jun 25 2015 08:35
yeah, very true ;-)
hemanth.hm
@hemanth
Jun 25 2015 09:19
Can var makeRegExp = pipe(map(add(__, '$')), join('|'), partialRight(RegExp, 'ig')) be reduced further?
Nate Abele
@nateabele
Jun 25 2015 15:30
@CrossEye So, I see people in here who post questions like, 'hey how do you do this thing', and you or someone else will come back with some pithy flourish of functional wizardry. What are some resources to learn and internalize the mindset of that style?
David Chambers
@davidchambers
Jun 25 2015 16:15
@nateabele, in my case it’s just been a matter of practice. After a while one starts to identify various patterns that can be transformed into something more elegant.
function(x) { return f(x); }, for example, is better written as f.
function(x) { return f(a, x); } is better written f(a), assuming f is curried, of course!
Having internalized a handful of these mechanical transformations it’s possible to fit lots of things into nice pipelines. :)
Nate Abele
@nateabele
Jun 25 2015 19:15
@davidchambers Yeah, my mind is still blown by converge() and useWith().
That was kind of my impetus for working on that Powerglove thing I posted a couple weeks ago. A full-featured version of that, plus some kind of interactive Ramda Cookbook would be a pretty powerful way of understanding functional transformation, and make pattern-spotting that much easier for beginners.
Vladimir Starkov
@iamstarkov
Jun 25 2015 19:22
fpeople, I need your help
I have a lot of constructions like this:
const contentText = compose(text, getContent)(input);
because I need to use compose to create new function, but then I immediately need to use it
some = compose(…)(input) — this seems a bit ugly to me
Raine Virta
@raine
Jun 25 2015 19:26
text(getContent(input))
Vladimir Starkov
@iamstarkov
Jun 25 2015 19:27
okie
Raine Virta
@raine
Jun 25 2015 19:28
or give compose(text, getContent) a name, const getText = compose(text, getContent)
Tobias Pflug
@gilligan
Jun 25 2015 20:41
damn, tern.js really struggles with ramda
i keep on running into timeouts with the tern.js vim plugin