These are chat archives for ramda/ramda

15th
Oct 2015
Hardy Jones
@joneshf
Oct 15 2015 01:20
@scott-christopher word.
hoffination
@hoffination
Oct 15 2015 03:31
Any tips for building a tree from an array of elements?
The elements have ids of parents that are also in the array. Just looking for some tips on which functions might help me accomplish this.
Hardy Jones
@joneshf
Oct 15 2015 04:16
sounds kind o like you want to do a toposort
Raine Virta
@raine
Oct 15 2015 04:16
@xgrommx not yet
Kaze no Koe
@KazeNoKoe
Oct 15 2015 08:34
Hi, can someone point me to an application implemented in Ramda? I got the gist of it but I'm having trouble figuring out how to use it properly.
Raine Virta
@raine
Oct 15 2015 08:34
what kind of app?
Kaze no Koe
@KazeNoKoe
Oct 15 2015 08:35
Any. Anything that works in the real world. A website scraper, or some kind of server, literally anything.
A client for Twitter or Reddit or whatever. It doesn't matter as long as it solves real problems.
Basically anything that would illustrate what you can't get from the API documentation: how to think in Ramda when facing real problems.
I hope I managed to explain myself :)
Raine Virta
@raine
Oct 15 2015 08:37
I have quite a lot of repos that use ramda link
Kaze no Koe
@KazeNoKoe
Oct 15 2015 08:43
Thanks. What language is this? "const main = () => {"
Raine Virta
@raine
Oct 15 2015 08:43
JS with ES6 arrow function
Kaze no Koe
@KazeNoKoe
Oct 15 2015 08:45
Oh haven't gotten there yet. Thanks for the examples.
Niloy Mondal
@niloy
Oct 15 2015 08:51
@KazeNoKoe Ramda enables functional style programming in JS, maybe you should learn some functional programming first using Haskell or Clojure to learn the basic concepts. I have personally learnt it via Haskell.
Raine Virta
@raine
Oct 15 2015 08:53
Mostly adequate guide is great learning material for FP in JS
Kaze no Koe
@KazeNoKoe
Oct 15 2015 08:56
I've gone through DrBoolean's guide, which is what convinced me to spend some time on this, however that guide lacks real world examples, which seems to be the case with all of the material I have managed to find on FP
Even now as I'm going through the results of a search for "require ramda" on github what I'm finding isn't really useful because it's either in coffescript (which I'm sure is great but I can't ALSO learn that while I'm learning another thing) or something that extends ramda or makes it work with some other framework.
Niloy Mondal
@niloy
Oct 15 2015 09:00
Take a look at the build script of Ramda written with Ramda, https://github.com/ramda/ramda/blob/master/scripts/build
Kaze no Koe
@KazeNoKoe
Oct 15 2015 09:05
That's more helpful, thanks, goes into some interesting things.
Going to digest it, see you!
James Forbes
@JAForbes
Oct 15 2015 09:59

Any one have a terse solution to this problem.

Say you have a function that accepts two parameters progress and total. progress being the number of bytes uploaded, and total being the total number of bytes to upload. Let's say you use this function render a progress bar.

Now, let's say amazon web services has a callback onprogress which receives an event which has two properties that map to the aforementioned properties. loaded and total.
Is there some function, or a composition of functions that would map those keys to positional arguments in a function application.

var progressHandler = function(progress, total){ 
  console.log('progress', progress, 'total', total)
}

var event = {
  loaded: 50,
  total: 100
}

var amazon = {}
//this works, but it relies on the keys being ordered... is there a better way?
amazon.onprogress = R.pipe(
  R.pick(['loaded', 'total']),
  R.values,
  R.apply(progressHandler)
)

amazon.onprogress(event)
Raine Virta
@raine
Oct 15 2015 10:01
R.props?
James Forbes
@JAForbes
Oct 15 2015 10:09

@KazeNoKoe

A website scraper

Be careful what you wish for. A practical example using Ramda: Scraping

This is quite old, and not the best example. But it is practical.

@raine props is perfect thank you!
so it would become
amazon.onprogress = R.pipe(
  R.props(['loaded', 'total']),
  R.apply(progressHandler)
)
Niloy Mondal
@niloy
Oct 15 2015 10:23
@JAForbes Great read 👍
James Forbes
@JAForbes
Oct 15 2015 10:25
Cheers @niloy
Julien Goux
@jgoux
Oct 15 2015 12:30
Hello, is there a built in function to transform an array of unique object into an object indexed by one of the object's key ?
[{id: 'foo',...}, {id: 'bar', ...}] => {'bar': {id:'bar'...}, 'foo': {id:'foo'}}
groupBy is close but it wraps the values into an array
Raine Virta
@raine
Oct 15 2015 12:33
compose groupBy and values?
eh
i think i meant groupBy and head
Julien Goux
@jgoux
Oct 15 2015 12:35
with a mapObj ?
Raine Virta
@raine
Oct 15 2015 12:35
yeah
ramda doesn't have a function for this, but groupBy is general enough to derive this more specific version
Julien Goux
@jgoux
Oct 15 2015 12:38
It worked ! Thank you @raine
I needed this in order to apply a diff algorithm on the data :D
James Forbes
@JAForbes
Oct 15 2015 12:40
@jgoux I count this as another request for indexBy thank you!
Raine Virta
@raine
Oct 15 2015 12:40
isn't indexBy different?
ah, no
Julien Goux
@jgoux
Oct 15 2015 12:41
@JAForbes Yes ! :D
James Forbes
@JAForbes
Oct 15 2015 12:41
yeah that cookbook indexBy is cooked
Julien Goux
@jgoux
Oct 15 2015 12:41
Wow I wasn't aware of a cookbook !
James Forbes
@JAForbes
Oct 15 2015 12:42
Its a cool definition, but it'd be great to have it built in, it's a very useful tool
Niloy Mondal
@niloy
Oct 15 2015 12:43
+1 for indexBy 👍
James Forbes
@JAForbes
Oct 15 2015 12:48

I'd probably define it as a single loop for performance.

Something like...

var indexBy = R.curry(function(prop, list){
  return list.reduce(function(indexed, val){
   return indexed[prop] = val[prop]
  }, {})
})

Would there be an indexWiththat accepts a predicate too? Or would it just be the same function? I think they'd be separate to keep with the Rich Hickey philosophy

Julien Goux
@jgoux
Oct 15 2015 13:05
I'm still discovering lenses, and it would be awesome to have a section in the cookbook about it
Niloy Mondal
@niloy
Oct 15 2015 13:22
R.contains behavior is different than String.prototype.contains on empty string, is that intended?
Julien Goux
@jgoux
Oct 15 2015 13:25
omit(['foo', 'bar'])(['foo','baz','bar']) => ['baz']
Is there a function for arrays to omit elements ?
instead of filter
It's basic but I can't find it in the doc
xD
Niloy Mondal
@niloy
Oct 15 2015 13:30
@jgoux See R.difference
Julien Goux
@jgoux
Oct 15 2015 13:32
@niloy Thanks !
Craig Dallimore
@craigdallimore
Oct 15 2015 15:55
Hey folks
I keep hitting this issue with objects which I'm sure has a simple pointfree solution but I cannot quite grasp it. I'll just make a contrived example of what I'm trying to do:
var item       = { id: 'abc' };
var collection = { xs: ['abc', 'def', 'ghi'] }

// How can I achieve
// peekInside :: item -> collection -> Boolean
// R.contains(foo.id, bar.xs) works, of course...

var peekInside = R.compose(
  R.contains,
  // ??? surely I can do something with R.prop here?
)

peekInside(item, collection);
David Chambers
@davidchambers
Oct 15 2015 15:59

@niloy:

R.contains behavior is different than String.prototype.contains on empty string, is that intended?

R.contains does not operate on strings.

Craig Dallimore
@craigdallimore
Oct 15 2015 16:01
I'm not trying to look in the string, rather to find if a string is present in a string array
Craig Dallimore
@craigdallimore
Oct 15 2015 16:10
However my issue is not really to do with contains - I'm trying to work out how to compose a function that returns the result of an operation on the properties of objects passed to it
Craig Dallimore
@craigdallimore
Oct 15 2015 16:15
var item1 = { num : 5 };
var item2 = { num : 7 };

var peekInside = R.compose(
  R.add,
  R.prop('num')
)

peekInside(item1)(R.prop('num', item2));
Another attempt at the same thing, to hopefully illustrate what I'm trying to do
The objective is to get to peekInside(item1, item2) or peekInside(item1)(item2) with the property lookups handled within the function
joneshf-work1
@joneshf-work1
Oct 15 2015 17:49
I just updated to 0.18, and it broke all my functors. Any idea where to start?
David Chambers
@davidchambers
Oct 15 2015 18:07
It may be related to ramda/ramda#1408, @joneshf-work1.
joneshf-work1
@joneshf-work1
Oct 15 2015 18:21
Ah, got it. Downgrade.
David Chambers
@davidchambers
Oct 15 2015 18:23
Could you provide an example of code which no longer works as expected?
Scott Sauyet
@CrossEye
Oct 15 2015 19:47
@joneshf-work1: if you're moving from 0.16 / 0.17 you might also want to look at #1391, which reverted some behaviour on compose / pipe.
Raine Virta
@raine
Oct 15 2015 20:21
can someone explain the relationship of a transducer and a transformation?
ah, seems to be explained in the docs
joneshf-work1
@joneshf-work1
Oct 15 2015 20:30
it was 0.17.1 to 0.18