These are chat archives for ramda/ramda

6th
Mar 2016
Risto Stevcev
@Risto-Stevcev
Mar 06 2016 04:40
Wrote a pure random generator: https://github.com/Risto-Stevcev/pure-random
Aldwin Vlasblom
@Avaq
Mar 06 2016 08:47
Ramda's toString is quite useful outside of Ramda context. I believe there is a port of it inside sanctuary-def, for example. I find myself wanting access to it without depending on the entirety of Ramda, more often than not. I'm wondering if anyone knows about some stand-alone version. All I could find is https://github.com/will-v-king/javascript-showMe, which seems to have a broader scope, is unmaintained, has no tests and isn't on NPM.
David Chambers
@davidchambers
Mar 06 2016 08:49
I'm in favour of creating a standalone repository in the ramda account on GitHub and publishing the package to npm. :)
R.toString is my favourite Ramda function!
Raine Virta
@raine
Mar 06 2016 08:55
Avaq, how do you use it
Aldwin Vlasblom
@Avaq
Mar 06 2016 09:05
For displaying values in error messages, mostly. To improve Expected string, got [object Object] kind of things.
Or f('object') -> Expected object, got object
I usually end up hacking together my own version of toString which tries to intelligently choose between .toString(x), JSON.stringify(x) and String(x), but it's a big hassle to get the edge-cases and I would love to just reach for Ramda's toString at that point, but I'm making some library otherwise unrelated.
Raine Virta
@raine
Mar 06 2016 09:18
what about util.inspect
Aldwin Vlasblom
@Avaq
Mar 06 2016 09:19
Node only
Raine Virta
@raine
Mar 06 2016 09:19
i see
Jeremy Wells
@jemmyw
Mar 06 2016 12:28
hi. is there a better way to express this to remove the ternary:
(tabs, currentTab) =>
    R.compose(
      R.map(tab =>
        li('.nav-item', [
          a(`.nav-link${R.equals(tab, currentTab) ? '.active' : ''}`, {attrs: {'data-tab': tab}, href: '#'}, [tab])
        ])),
      R.pluck('name'))(tabs))
Hardy Jones
@joneshf
Mar 06 2016 15:16
@jemmyw using purely css tabs would remove that ternary :). Some examples: http://bit.ly/1LJER8f, http://bit.ly/1oZXbiX.
ugh
gitter is too smart
Outsmarted gitter! :D
Raine Virta
@raine
Mar 06 2016 15:27
and sometimes you can do stuff like a('.nav-link', { class: { active: tab === currentTab } })
should've copypasted a backtick, i'm unfamiliar with this keyboard
Jeremy Wells
@jemmyw
Mar 06 2016 15:28
thanks, I think I’ll do a pure css version. I just wondered if there was a way to do it in ramda that looked less ugly than my current version
Hardy Jones
@joneshf
Mar 06 2016 15:34
You could also play around with ifElse
erm...
ifElse
umm
R.ifElse
Hardy Jones
@joneshf
Mar 06 2016 15:34
@raine nice, docs and source :)
@ram-bot @jemmyw
const currentTab = 'home';
const isActive = R.ifElse(R.equals(currentTab), R.always('.active'), R.always(''));
isActive('help');
let's try that again
@ram-bot
const currentTab = 'home';
const isActive = R.ifElse(R.equals(currentTab), R.always('.active'), R.always(''));
isActive('help');
ram-bot
@ram-bot
Mar 06 2016 15:37
''
Hardy Jones
@joneshf
Mar 06 2016 15:37
and...
@ram-bot
const currentTab = 'home';
const isActive = R.ifElse(R.equals(currentTab), R.always('.active'), R.always(''));
isActive('home');
ram-bot
@ram-bot
Mar 06 2016 15:37
'.active'
Hardy Jones
@joneshf
Mar 06 2016 15:38
though, the ternary in that case is probablymuch clearer...
Risto Stevcev
@Risto-Stevcev
Mar 06 2016 15:38
I think thatR.gt, R.gte, R.lt, and R.lte should have it's args reversed
Getting a range between 0 and 10 looks a little strange
@ram-bot
R.both(R.lt(0), R.gt(10))(4)
ram-bot
@ram-bot
Mar 06 2016 15:40
true
Risto Stevcev
@Risto-Stevcev
Mar 06 2016 15:40
Having it look better introduces the butts
ram-bot
@ram-bot
Mar 06 2016 15:40
false
Risto Stevcev
@Risto-Stevcev
Mar 06 2016 15:41
@ram-bot
R.both(R.flip(R.gt)(0), R.flip(R.lt)(10))(4)
ram-bot
@ram-bot
Mar 06 2016 15:41
true
Hardy Jones
@joneshf
Mar 06 2016 15:55
@ram-bot learn gt = ramda/ramda#175, ramda/ramda#388, ramda/ramda#1363, ramda/ramda#1497, ramda/ramda#1539
hmm, does it not do that anymore?
In any case, @Risto-Stevcev ^
Stefano Vozza
@svozza
Mar 06 2016 16:37
@ram-bot
R.both(R.gt(R.__, 0), R.lt(R.__,10))(4)
ram-bot
@ram-bot
Mar 06 2016 16:37
true
David Chambers
@davidchambers
Mar 06 2016 16:41

I usually end up hacking together my own version of toString which tries to intelligently choose between .toString(x), JSON.stringify(x) and String(x)

@Avaq, it sounds as though there are some values for which R.toString is not doing a good job. If so, could you open an issue? I'd love to make the function even better.

Risto Stevcev
@Risto-Stevcev
Mar 06 2016 17:17
@svozza Ah nice, thanks
Forgot about R.__
Aldwin Vlasblom
@Avaq
Mar 06 2016 17:43
@davidchambers Did you interpret my remark out of its context? I was talking about what I end up doing in the situations where I wish I had access R.toString without everything else on R. :)
David Chambers
@davidchambers
Mar 06 2016 17:44
Oh, I see! Thanks for setting me straight.