These are chat archives for ramda/ramda

10th
Sep 2016
Keith Alexander
@kwijibo
Sep 10 2016 08:28
Dispatches to the aperture method of the second argument, if present.
what type of object has an aperture method?
I don't see it in fantasy-land , or on Array
Michael Hurley
@buzzdecafe
Sep 10 2016 11:09
@kwijibo good question -- that is an error IMO
Craig Dallimore
@craigdallimore
Sep 10 2016 12:00
Hello folks
Would you be interested in a pretty print button for the Try Ramda page?
I'll create an issue / PR if there is interest.
;)
Keith Alexander
@kwijibo
Sep 10 2016 13:20
@buzzdecafe I was scratching my head wondering what the generalisation beyond lists would be :)
Michael Hurley
@buzzdecafe
Sep 10 2016 13:21
@kwijibo me too
@craigdallimore :+1:
LeonineKing1199
@LeonineKing1199
Sep 10 2016 15:14

@craigdallimore

https://imgur.com/a/9rCAU

Yes, please make this happen!

Craig Dallimore
@craigdallimore
Sep 10 2016 15:43
:D I see it is already present.
LeonineKing1199
@LeonineKing1199
Sep 10 2016 15:45
That's awesome then! The world can always use more formatted whitespace :)
Craig Dallimore
@craigdallimore
Sep 10 2016 15:47
I was finding it difficult to see if I was transforming deeply structures correctly and had to keep pasting into a JSON formatter. Delighted to help in a small way.
LeonineKing1199
@LeonineKing1199
Sep 10 2016 15:51
Making code more readable is nothing short of a huge contribution.
Rob Halff
@rhalff
Sep 10 2016 15:55
Perhaps add highlighting? https://highlightjs.org/
Michael Hurley
@buzzdecafe
Sep 10 2016 16:20
Highlighting would be nice -- i'd want to be sure the highlighting was the same on left and right
Eugene Lerman
@airbugg
Sep 10 2016 16:53
Hi guys! I was wondering if anyone here could help me with a transducer related pickle :) As an aside, since I have the chance, I just wanted to mention that I've been using Ramda professionally for about a year now and I feel blessed that I stumbled across this wonderful library when I was just beginning to learn JS. It made the learning curve much steeper, but I feel I've become a much better programmer than I would have otherwise. So just a huge thanks for that! Anyways, I've been messing with transducers for about a week for a new data-heavy project at work and it's been a blast so far. I did stumble across a problem I'm having trouble solving the point-free, Ramda way. Suppose I have an array of objects of the following form:
ugh, sorry. clumsy. still learning Gitter.
Eugene Lerman
@airbugg
Sep 10 2016 17:04
const node = {
  "data": {
      "key_1": val,
      "key2": val,
      "key_3": val,
      // etc ...
  },
  "group": \\ either "node" or "edge", but doesn't really matter
}

The nested data object contains key-value pairs. I don't care about the values, but I do count the number of keys according to an arbitrary predicate (for example, key_3 and key_something would count as one occurrence, since they both start with key).
What I would like to do is to append the key count to the outer object (let's say add a dataCount key to the node object ). In other words, the resulting new node should look like this:

const node = {
  "data": {
      "key_1": val,
      "key2": val,
      "key_3": val,
      // etc ...
  },
  "dataCount": 2,
  "group": \\ either "node" or "edge", but doesn't really matter
}

I am able to correctly apply the predicate and get the correct count for each node object in an array, but by focusing on the nested data object I'm essentially "losing" the outer object while mapping and so I can't use R.assoc, for example, to append the count.
I'll be happy to elaborate if my explanation is too convoluted, and happier still if someone's interested in helping me :)

Craig Dallimore
@craigdallimore
Sep 10 2016 17:10
OK, so the predicate is to do with the key name? And the dataCount has the number of keys that return true for the predicate?
Eugene Lerman
@airbugg
Sep 10 2016 17:15
@craigdallimore Right, predicate was a stupid choice hehe. This is what the counting function does (It returns a Number. apologies for calling it a predicate):
const countNormalizedKeys = R.compose(
  R.length, 
  R.uniq, 
  R.map(
    R.ifElse(
      containsHyphen, 
      R.compose(R.take(1), R.split('_')), 
      R.identity
    )
  )
);
(on an unrelated note, is there a way to auto-indent the code snippets in the markdown editor somehow?)
Craig Dallimore
@craigdallimore
Sep 10 2016 17:19
is there a way to auto-indent the code snippets in the markdown editor somehow
No idea. It would be nice! I think maybe paste in from your actual editor :/
Rob Halff
@rhalff
Sep 10 2016 17:21
@craigdallimore markdown editor?
Craig Dallimore
@craigdallimore
Sep 10 2016 17:23
@airbugg is this the objective?
Rob Halff
@rhalff
Sep 10 2016 17:27
@craigdallimore I don't think it's enable, the editor used is codemirror, which should be capable of that: https://codemirror.net/2/demo/formatting.html
many features could be enabled actually.
I guess it's 'Try Ramda' and not 'Ramda IDE' :-)
Craig Dallimore
@craigdallimore
Sep 10 2016 17:30
@rhalff are we talking about the gitter markdown editor or something else?
Rob Halff
@rhalff
Sep 10 2016 17:30
@craigdallimore I was talking about ramda editor. sorry..
Craig Dallimore
@craigdallimore
Sep 10 2016 17:30
I suspect @airbugg was referring to the gitter MD editor, I'm unsure. :)
OK
Taking a look at highlightjs however ;)
Rob Halff
@rhalff
Sep 10 2016 17:33
I had a try also, but got confused by the build process.
Eugene Lerman
@airbugg
Sep 10 2016 17:34
@craigdallimore Thanks, I haven't considered objOf (or known of its existence lol). Would that compose well with other transducers? I'm asking because the goal is to eventually have many transducers (such as the one described) arbitrarly composed and mapped over a list of node objects. I opted for transducers because the don't create intermediate containers and so having a bunch of the mapping and re-creating lists might become expensive.
@rhalff Yup, I was talking about the gitter editor. Probably best to just copy from the editor like @craigdallimore suggested :)
Craig Dallimore
@craigdallimore
Sep 10 2016 17:39
@airbugg oh I see, there is a collection of nodes. I'm not sure what I offered is right for your needs, will have a think about it
Craig Dallimore
@craigdallimore
Sep 10 2016 17:57
@rhalff got some kind of highlighting working, obviously not the right theme. Also I'll need to rethink the pretty-print, as it (crudely) works on the presumption that the content of the output element is just a textNode, whereas highlightjs will put a lot of DOM structure in there.
https://i.imgur.com/p5FAeRz.png
I'll try and get you a PR tomorrow with both doing the right thing. Alas I need to go out now.
Good top on highlightjs! Works like a charm.
Rob Halff
@rhalff
Sep 10 2016 17:59
@craigdallimore great, looks nice.
Craig Dallimore
@craigdallimore
Sep 10 2016 17:59
:+1: thx g2g
Eugene Lerman
@airbugg
Sep 10 2016 18:10
@craigdallimore thanks for the help! Anyone else wants to take a shot at this? :P
Craig Dallimore
@craigdallimore
Sep 10 2016 20:37
Weird, the dracula theme from highlightjs does not match the dracula theme for Codemirror
Rob Halff
@rhalff
Sep 10 2016 20:39
that's inconvenient
Rob Halff
@rhalff
Sep 10 2016 20:44
Craig Dallimore
@craigdallimore
Sep 10 2016 20:55
https://i.imgur.com/7aGjWJX.png Ok got pretty print working again. I'll look at the colour codes now, thanks :)
Craig Dallimore
@craigdallimore
Sep 10 2016 21:28
https://i.imgur.com/JUkrXq7.png Colour codes worked reasonably well - alas not everything is given a class by highlightJS
Rob Halff
@rhalff
Sep 10 2016 21:33
@craigdallimore a b and c are probably stylable with .hljs-variable ? it looks almost right.. :)