Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 22:17
    CrossEye commented #2779
  • Jan 31 2019 21:04
    ArturAralin commented #2779
  • Jan 31 2019 20:08
    CrossEye commented #2779
  • Jan 31 2019 18:56
    buzzdecafe commented #2631
  • Jan 31 2019 18:09
    ArturAralin commented #2779
  • Jan 31 2019 16:18
    CrossEye commented #2779
  • Jan 31 2019 16:10
    CrossEye commented #2631
  • Jan 31 2019 16:06
    CrossEye commented #2777
  • Jan 31 2019 14:44
    ArturAralin opened #2779
  • Jan 31 2019 07:39
    inferusvv commented #2631
  • Jan 31 2019 03:07
    sespinozj commented #2771
  • Jan 31 2019 02:33
    machad0 commented #2771
  • Jan 31 2019 02:26
    JeffreyChan commented #2777
  • Jan 30 2019 14:30
    CrossEye closed #2777
  • Jan 30 2019 12:13
    vanyadymousky updated the wiki
  • Jan 30 2019 01:42
    JeffreyChan commented #2777
  • Jan 29 2019 21:06
    vanyadymousky updated the wiki
  • Jan 29 2019 16:28
    CrossEye commented #2777
  • Jan 29 2019 15:50
    mbostock commented #2772
  • Jan 29 2019 15:48
    CrossEye commented #2772
Ghost
@ghost~60950c966da03739847c0a83
how do I convert this to ramda? [{ id: '0A' }, { id: '0F' }].map((id) => Buffer.from(id, 'hex'))]
tobias11
@tobias11:matrix.org
[m]

I have quite a bit of trouble wrapping my head around "advanced" (at least to me) concepts like lift and either (in some contexts). For example, running either with two arrays seems to reflect some kind of broadcasting (as known in numpy, python). I cannot detect that in the definition, though. So, I assume that such features stem from the implications of the fantasy-land spec.

Question: What would be a good resource to get a deeper understanding of Ramda? I already ordered a book on category theory for CS by B. Pierce.

Disclaimer: I am a Ramda beginner but enthusiastic to learn more about its foundation, not only using it on the surface.
wangzengdi
@adispring
@tobias11:matrix.org Ramda focus more on compose functions and data immutiblity. You don't need category theory at beginning, if you just want to learn and write something with Ramda.
zhangyd
@zydmayday

Hey guys! I am trying to extract the indexes from an Array.

const indexesFrom = pipe(length, range(0))

Is this the correct way to do that?

Nicolás Fantone
@nfantone
@zydmayday I'd do: const indexes = list => range(0, list.length)
Nicolás Fantone
@nfantone
if you're going for a point-free version, take a look at useWith and converge: useWith(range(0), [length]) or converge(range, [always(0), length])
9 replies
Daniel Maricic -- Woss
@woss:matrix.org
[m]
👋
zhangyd
@zydmayday
Maybe I can post here.
Yes actually it confuses me a lot that I can do the same thing with many different ways.
Do we have some principles that should use some other functions than pipe/compose if we have.
Daniel Maricic -- Woss
@woss:matrix.org
[m]
hi, do you guys have in plan to have the PWA for the docs? it's so much nicer to have it 'installed' and accessible when offline
if you point me in right direction on docs generation i can help
Nicolás Fantone
@nfantone
@woss:matrix.org Well... docs can be found here: https://github.com/ramda/ramda.github.io
2 replies
instructions on how to serve and build them are also there
Charles Hughes
@chughes87
Is doing something like this counter to the spirit of what over/lens is intended for? I feel like it is but I wonder if I'm mistaken?
overP(
  lens(identity, (inventory, config) => ({ inventory, config })),
  getInventoryForConfig,
)
7 replies
Joshua Travis
@jktravis

@zydmayday I'd do: const indexes = list => range(0, list.length)

Wouldn't R.keys(list) do it?

5 replies
Charles Hughes
@chughes87
Has anyone here tried making an extension for an editor like VS Code or emacs that allows for a good debugging experience with Ramda? I've been wondering about how this could be done and I'm not sure it would be easy..
2 replies
Charles Hughes
@chughes87
Hmmm. does anyone have a particular strategy for ensuring there are no UnhandledPromiseRejectionWarnings in their projects? Eventually unhandled promise rejections will result in process termination so if you're just ignoring these, you're forcing your project to be locked into a certain Node version..
15 replies
hazem-hosny
@hazem-hosny
No This Is Bibe Only In This Union
Spain
oomusou
@oomusou
Is there any Ramda function like Object.entries() ? Thanks
Joshua Travis
@jktravis
toPairs I think.
Nicolás Fantone
@nfantone
just bear in mind that it will only return entries from an object's own properties (i.e.: Object.hasOwnProperty) - which is exactly what Object.entries does as well
Nicolás Fantone
@nfantone
in fact, if your runtime supports Object.entries, I would probably use that instead
Charles Hughes
@chughes87
I love how clean going toPairs....fromPairs is though
2 replies
André Letterer
@111andre111
Hi folks, anybody knows why this groupBy function using fx in ramda throws an error?
curl -s "https://api.github.com/repos/facebook/react/commits?per_page=100" | fx "groupBy(\"commit.author.name\")" "mapValues(size)" toPairs "sortBy(1)" reverse "take(10)" fromPairs
   groupBy("commit.author.name") mapValues(size) toPa...
TypeError: keyFn is not a function
    at XWrap.f (/Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/reduceBy.js:55:17)
    at XWrap.module.exports.XWrap.@@transducer/step (/Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/internal/_xwrap.js:10:17)
    at _arrayReduce (/Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/internal/_reduce.js:11:36)
    at _reduce (/Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/internal/_reduce.js:44:14)
    at reduceBy (/Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/reduceBy.js:54:12)
    at /Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/internal/_dispatchable.js:39:15
    at /Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/internal/_curryN.js:37:27
    at /Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/internal/_arity.js:6:49
    at /Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/internal/_checkForMethod.js:22:10
    at /Users/username/.nvm/versions/node/v10.24.1/lib/node_modules/ramda/src/internal/_curry2.js:20:46
26 replies
André Letterer
@111andre111
Ramda 0.24.1
alnj
@alnj
hey i have two questions
first, is there anything wrong with this style of fake partial application? that's how i've been doing it until now:
const addFive = x => add (5, x)
const add = (x, y) => x + y
11 replies
alnj
@alnj

second, i tried ramda's curry and __ but i'm running into an issue; i strongly favor having a module's exported members at the top of my file, but using curry and potentially __ it won't let me use partial application on a curried function declared lower in the module

export const incr = add (1)
export const addFive = add (__, 5)
// ReferenceError: Cannot access 'loadModule' before initialization

const add = curry ((x, y) => x + y)

is there any way around that?

5 replies
citeru
@citeru
is there a R.both with n arguments
9 replies
salmondorf
@salmondorf:matrix.org
[m]

Hey folks. I'm working on a proof of concept for translating some existing code into code using Ramda. Having some trouble identifying what would be the best way to go about this, was hoping for some help.
I've got data that looks like this:

item = {
    slug: 'foo-bar-content', // identifies this content
    stationSlug: 'my-station', // identifies the original publisher of this content
    primaryCategory: 'primary-category', // how the original publisher categorizes this content
    secondaryCategory: 'secondary-category', // sub-category by the original publisher

    subscriptions: [ // a list of subscribers to this content
      {
        stationSlug: 'other-station', // identifies a subscriber
        primaryCategory: 'other-primary-cat', // how the subscriber categorizes this content
        secondaryCategory: 'other-secondary-cat' // sub-category by the subscriber
      }
    ]
  };

I'd like to create a function with the following signature:
mySubscription('my-station-slug', content) // -> {stationSlug:'my-station-slug', ...} where the returned object is the entry from the subscriptions array
Here's what I have so far:

const R = require('ramda'),

  // subscriptions(content) -> [{stationSlug:'other-station'}] (the list of subscribers)
  subscriptions = R.prop('subscriptions'),

  // byStation('station-slug') -> (obj) => obj.stationSlug === 'station-slug' (a predicate returning whether the given item belongs to the given station) (could be used on top-level object, or the subscription entry)
  byStation = R.propEq('stationSlug'),

  // mySubscription('my-station-slug', content) -> {stationSlug:'my-station-slug', ...} (desired signature/result)
  mySubcription = R.compose(
    R.find(byStation('how do I get the first param of mySubscription() here?')),
    subscriptions
    // ...?
  );

Am I at least on the right track?

1 reply
salmondorf
@salmondorf:matrix.org
[m]
I'm trying to create a function which I can pass ('station-slug', content) and have it return the corresponding entry in content.subscriptions (i.e. the entry in the subscriptions array with a matching stationSlug)
2 replies
so in the example above, my end goal is to be able to call mySubscription('other-station',item) and have it return {stationSlug:'other-station', primaryCategory:'other-primary-cat', secondaryCategory:'other-secondary-cat'}
the rest of what I have there is just me trying to work my way there, I'm pretty new to Ramda so I'm stumbling around. The comments are me mentally thinking of what each line is/does
salmondorf
@salmondorf:matrix.org
[m]
Yeah, pretty much that. I figured I was over thinking it.
Thanks
Joshua Travis
@jktravis

Is there a point-free way of doing this?

const error = {
    response: {
        data: {
            Message: 'Not found'
        },
        status: 404,
    },
}

R.converge(
    (message, status) => ({ message, status }),
    [
        R.pathOr('No message provided', ['response', 'data', 'Message']),
        R.pathOr('No status code provided', ['response', 'status'])
    ]
)(error) //=> { message: 'Not found', status: 404 }

I thought about chain, but didn't know if there was a shorter, less verbose way.

R.compose(
    R.pick(['status', 'message']),
    R.chain(
        R.assoc('status'),
        R.pathOr('No status code provided', ['response', 'status'])
    ),
    R.chain(
        R.assoc('message'),
        R.pathOr('No message provided', ['response', 'data', 'Message']),
    )
)(error) //=> { status: 404, message: 'Not found' }
4 replies
citeru
@citeru
guys is there a way to refactor this :
x(a) ? x(a-1) || x(b) : x(b-1)
5 replies
George Nixon
@pipedreambomb
is there a way to supply a function to adjust to supply it with an index? for instance
const array = [1, 2, 3]
R.adjust(R.findIndex(R.gte(2)), R.inc) // => [1, 3, 3]
48 replies
George Nixon
@pipedreambomb

just wondering if anyone has preferences of one unit test library over another for working with ramda?

i'm using jest, but it's kinda awkward that the idiom is expect(data).toBlahBlah(). It's obviously not easy to curry and put in something like a ramda pipe.

i'd like to be able to do something like

pipe(
  map,
  reduce,
  assert.isEqual(42)
)(data)

i noticed Chai lets you use that assertion style. is that my best bet?

Joshua Travis
@jktravis

I don't know if I'd switch out my entire testing library to do that when one could just do

pipe(
  map,
  reduce,
  result => expect(data).isEqual(42)
)(data)

Or

const assertEqual = R.curry((a, b) => {
   expect(b).toEqual(a);
})
pipe(
  map,
  reduce,
  assertEqual(a),
)(data)
George Nixon
@pipedreambomb
i just rewrote my whole code base to use ramda instead of lodash, so that's not an issue :) i'm not on the clock, it's a personal project and i'm having fun learning functional programming for the first time
i like your first idea, i might use that
i just worked out it's not going to work (out of the box, anyway) with Chai as the functions still aren't curried, so i can't do assert.equal(42)(<data>). like you say i can curry manually, but i'm worried i'll end up having a huge list of different curried assertions
George Nixon
@pipedreambomb
looks like i can use this with Chai, so maybe not too bad:
      pipe(
        pluck('shells'),
        filter(equals(2)),
        curry(assert.lengthOf)(1)
      )(grid()[5])
nah actually it doesn't work
George Nixon
@pipedreambomb
guys, i found one! https://github.com/TylorS/4.5
Nicolás Fantone
@nfantone
not really sure what you're going for here (I don't know that curry-ing my assert functions would bring any benefits to the table)... but 4.5 looks like a nice thing to play around with
George Nixon
@pipedreambomb

i ended up writing my own curried assert function as an adapter to jest assertions. i can now write my tests with the pipe, and i think they look very clear and readable and clean, personally. even when you want to test something complicated, you can clearly see what each step is doing in your assertion

    test.each([[1, 5, 66], [2, 4, 5]])('adds several tiles matching nextTile', (...args) => {
      // arrange
      const expected = [...args]
      const testStore = createTestStore(expected)

      // act
      const act = () => testStore.dispatch({ type: 'tiles/addNextTileToColumn', payload: { column: 0 } });
      times(act, 3)

      // assert
      pipe(
        nth(0),
        reverse,
        take(3),
        pluck('value'),
        assert(equals(expected))
      )(testStore.getState().game.grid)
    })

i'm happy with it, anyway. notice the assert function can even take ramda Relation functions like equals(), gte() or whatever