These are chat archives for ramda/ramda

Mar 2017
James Forbes
Mar 15 2017 01:01 UTC

@Bravilogy I use them for a permissions system in my api. When I do it in JS I use a library I wrote: to make it seem less arcane.

In postgres, I use operators like bit_or.

You can do cool stuff like:

var auth_permissions_read = group_permissions.reduce( flagon.merge, 0)

And in sql:

      case when GE.group_permissions_read
        then P.permission_flag else 0
  ) as auth_permissions_read

I prefer not to use | / & directly, because its not immediately obvious to other people on the team that they aren't meant to be || or &&.

And in some cases, its super hard to read e.g. flagon.contains equates to: B == 0 || ((A & B) == B)

It'd be fun to implement bit flag operations as monoids. Then you could have merge be OR.concat and toggle could be XOR.concatetc
James Forbes
Mar 15 2017 01:19 UTC
Maybe something like this?
const OR = {
  of: a => ({
    fold: () => a
    ,toString: () => [
    ,concat: b => OR.of(b.fold() | a)
  ,concat: (a,b) => a.concat(b)
  ,empty: () => OR.of(0)

var f = pipe(
  ,reduce(OR.concat, OR.empty())

f([0b001, 0b010, 0b100])
//=> 0b111
Kurt Milam
Mar 15 2017 07:19 UTC
@JAForbes I'm pretty sure someone posted to this gitter a link to a functional bitwise operators library they wrote, but my google fu is failing me at the moment.
James Forbes
Mar 15 2017 08:11 UTC
Been fooling around with this today: @kurtmilam
Hey can someone show a usage of Alt? Its behaviour seems wide open from the spec. What's a common usage?
Kurt Milam
Mar 15 2017 08:39 UTC
Adam Szaraniec
Mar 15 2017 08:47 UTC
Wow, I've just realized that on documentation there is tiny text "expand parameters", which describe parameters. I am using Ramda for ~3 months :smile:
Adam Szaraniec
Mar 15 2017 13:46 UTC
Hey, I need tip how can I replace placeholders in string
I've did
Any ideas how to improve it?
Adam Szaraniec
Mar 15 2017 13:49 UTC
Hey, thx, however think its not suitable here
I need to allow to set custom placeholder {{{ }}} and text is stored as plan text
Denis Stoyanov
Mar 15 2017 13:49 UTC
you can do it like "formatsome string with placeholders"
Adam Szaraniec
Mar 15 2017 13:50 UTC
Not sure if I catch what you mean.
Syaiful Bahri
Mar 15 2017 14:21 UTC
@mimol91 maybe using regex to replace the placeholder. rather than iterate the object keys like that.
Adam Szaraniec
Mar 15 2017 14:32 UTC
R.replace is using regexp internally. What do you mean by that?
Matthew Willhite
Mar 15 2017 14:38 UTC
const text = `
  Demo variable = {{{demo}}} 
  Foo = {{{foo}}}

const vars = {
  demo: 'I m demo!',
  foo: 'fooVar'

text.replace(/{{{(\w+)}}}/g, function (match, key) {
  return vars[key];

//=> "\n  Demo variable = I m demo! \n  Foo = fooVar\n”
The replace() method returns a new string with some or all matches of a pattern replaced by a replacement.
Syaiful Bahri
Mar 15 2017 14:39 UTC
i mean like this: your implementation create intermediate string as much as keys on the object
Adam Szaraniec
Mar 15 2017 15:18 UTC
@miwillhite thanks
Piet Vandeput
Mar 15 2017 17:46 UTC
@miwillhite it took me some time thinking it through but I managed to finish it points-free:
const ary2 = R.pipe(R.nAry(2), R.curry);
const testPermissionsPath = testPath(['settings', 'permissions']);
const testPermissionsAnd = R.useWith(R.both, [R.identity, testPermissionsPath]);
const filterRouteBy = ary2(R.pipe(testPermissionsAnd, R.filter));
const filterByPermissionsTestAnd = R.pipe(filterRouteBy, R.uncurryN(2));
used as: (isNavBarRoute) => (hasSomePermissions) => (routes) => (filteredRoutes) =D
Matthew Willhite
Mar 15 2017 18:19 UTC
oh useWith, that is what I needed yesterday! ;)
Mar 15 2017 20:09 UTC
My current understanding of Alt is that it's much like Semigroup, except that you're not allowed to look at the inner values, only the types. It's a "higher-level" form of taking two things and getting one thing from it. But because you can't look at the inner values you can't do this by combining, you can only do it by choosing.
Mar 15 2017 20:22 UTC
So one logic for M.alt(M) with a Maybe would be "take the first M unless it's a Nothing, in which case take the second" or "first Just always wins"
Mar 15 2017 20:27 UTC
One I've heard described for sequential Tasks would be "run the first M and if it succeeds, return it, but if it fails, then and only then run the second Task and return it" (whereas parallel Tasks would run both and take the one that finished first, or the first one in a "tie" though in practice I don't think a "tie" is possible)
Galileo Sanchez
Mar 15 2017 23:16 UTC
would pick work on buffers? pick([1,3,5], Buffer("af3de4d60935f3", "hex")) === Buffer("3dd635", "hex")