These are chat archives for ramda/ramda

30th
Oct 2015
joneshf-work1
@joneshf-work1
Oct 30 2015 00:07
Is there a window like function?
ah aperture
joneshf-work1
@joneshf-work1
Oct 30 2015 00:20
how about a transpose?
Scott Christopher
@scott-christopher
Oct 30 2015 00:39
@joneshf-work1 :point_up: October 5, 2015 10:22 PM
If that's what you mean by transpose, there's nothing baked into ramda (that I'm aware of)
joneshf-work1
@joneshf-work1
Oct 30 2015 00:42
hmm
that's not ideal
Scott Christopher
@scott-christopher
Oct 30 2015 00:44
what's wrong with this? :P
R.converge(R.reduce(R.zipWith(R.flip(R.append))), R.compose(R.map(R.of), R.head), R.tail)
joneshf-work1
@joneshf-work1
Oct 30 2015 00:45
> var transpose = R.converge(R.reduce(R.zipWith(R.flip(R.append))), R.compose(R.map(R.of), R.head), R.tail)
undefined
> transpose([[1,2,3], [4,5,6], [7,8]])
[ [ 1, 4, 7 ], [ 2, 5, 8 ] ]
Prelude> :m + Data.List
Prelude Data.List> transpose [[1,2,3], [4,5,6], [7,8]]
[[1,4,7],[2,5,8],[3,6]]
I want that behavior
also, I didn'tmean your solution wasn't ideal.
I meant that it doesn't exist in thelibrary isn't ideal.
joneshf-work1
@joneshf-work1
Oct 30 2015 00:54
apparently I can't even find one on npm either.
Aldwin Vlasblom
@Avaq
Oct 30 2015 08:43
How would I go about renaming a property with Ramda: renameProp('b', 'c', {a: 1, b: 2}) //{"a": 1, "c": 2}?
Zero instances of the word "rename" found in the docs or the cookbook. Is this a weird request? It's either a really uncommon case, or a really easy problem to solve. :P
Raine Virta
@raine
Oct 30 2015 08:50
not really, I almost needed that a while ago
Keith Nicholas
@keithn
Oct 30 2015 09:23
var rename = R.curry((x,y) => R.cond([ [R.equals(x), R.always(y)], [R.T, R.identity] ])) renameProp = R.curry((key, name, obj) => R.zipObj(R.map(rename(key,name),R.keys(obj)), R.values(obj)))
Raine Virta
@raine
Oct 30 2015 09:24
@keithn using fenced code block is more readable
Keith Nicholas
@keithn
Oct 30 2015 09:24
yeah, just trying to work out how to do that
Raine Virta
@raine
Oct 30 2015 09:24

<three back ticks>
codez

<three back ticks>

Keith Nicholas
@keithn
Oct 30 2015 09:24
var rename = R.curry((x,y) => R.cond([ [R.equals(x), R.always(y)], [R.T, R.identity] ])) renameProp = R.curry((key, name, obj) => R.zipObj(R.map(rename(key,name),R.keys(obj)), R.values(obj)))
Raine Virta
@raine
Oct 30 2015 09:24
and you can edit your message
line break after first ```
Keith Nicholas
@keithn
Oct 30 2015 09:25
var rename = R.curry((x,y) => R.cond([
  [R.equals(x), R.always(y)],
  [R.T, R.identity]
]))
renameProp = R.curry((key, name, obj) => R.zipObj(R.map(rename(key,name),R.keys(obj)), R.values(obj)))
not sure how good that is though :)
Denis Stoyanov
@xgrommx
Oct 30 2015 09:26
some preudo code => c: value of b, remove b.
Keith Nicholas
@keithn
Oct 30 2015 09:35
renameProp = (k,n,l) => R.merge(R.omit([k],l),R.objOf(n,l[k]))
works as long as the thing to rename exists.
Aldwin Vlasblom
@Avaq
Oct 30 2015 09:38
That one is pretty. :)
Raine Virta
@raine
Oct 30 2015 09:40
const { assoc, curry, dissoc, prop } = require('ramda')

const rename = curry((a, b, obj) =>
  dissoc(a, assoc(b, prop(a, obj), obj)))

rename('a', 'b', { a: 1 })
Keith Nicholas
@keithn
Oct 30 2015 09:44
problem is if its ... rename('c', 'b', { a: 1 })
Raine Virta
@raine
Oct 30 2015 09:55
if the data is not uniform, then you will probably have many issues and have to be careful
it might be better to normalize it in a first pass instead of making everything safe in the pipeline
Denis Stoyanov
@xgrommx
Oct 30 2015 09:55
Raine Virta
@raine
Oct 30 2015 09:57
@xgrommx read the readme and i have no idea why i would use it
Julien Goux
@jgoux
Oct 30 2015 10:09
Hello
Niloy Mondal
@niloy
Oct 30 2015 10:18
I created a PR for implementing generators in Ramda, would be nice if someone can take a look at it ramda/ramda#1482
Raine Virta
@raine
Oct 30 2015 10:20
@niloy looks interesting, thanks for taking the effort
Niloy Mondal
@niloy
Oct 30 2015 10:20
nps 👍
Arve Knudsen
@aknuds1
Oct 30 2015 10:29
I have a KeyedCursor to an object, how do I set a value in the object?
Ah, think I got it, I hadn’t used an immutable for the object
Julien Goux
@jgoux
Oct 30 2015 11:09
Is it possible to put synchronous functions in pipeP ?
If I have both sync and async functions in the chain
Raine Virta
@raine
Oct 30 2015 11:10
no
Julien Goux
@jgoux
Oct 30 2015 11:11
ok, so I have to turn all my functions async
Raine Virta
@raine
Oct 30 2015 11:11
no
Julien Goux
@jgoux
Oct 30 2015 11:11
lol
Raine Virta
@raine
Oct 30 2015 11:11
you lift your functions to work in promise context
Julien Goux
@jgoux
Oct 30 2015 11:12
How can I do that ?
Raine Virta
@raine
Oct 30 2015 11:15
var getList = R.always(Promise.resolve([1, 2, 3]));
var then = R.invoker(1, 'then');

pipe(
  getList(),
  then(R.map(R.inc))
);
Julien Goux
@jgoux
Oct 30 2015 11:16
Oh
I now understand a little better what lifting means :D
Raine Virta
@raine
Oct 30 2015 11:17
it's not exactly lifting here
but same idea, i think
Julien Goux
@jgoux
Oct 30 2015 11:17
What is lifting ?
You push computation in the context of a monad ?
Raine Virta
@raine
Oct 30 2015 11:18
making a function so that it can map over a functor
Julien Goux
@jgoux
Oct 30 2015 11:18
ok
Thanks @raine
Raine Virta
@raine
Oct 30 2015 11:19
pipeP used to be so that it took both functions that returned a promise and functions that returned a value not in promise context
Julien Goux
@jgoux
Oct 30 2015 11:20
ok, so now it's more explicit
Raine Virta
@raine
Oct 30 2015 11:21
I think pipeP is useless now
ramda/ramda#1314
Scott Sauyet
@CrossEye
Oct 30 2015 11:30
@joneshf: no access to gitter from work machines, so I can't easily show it here, but I needed a transpose yesterday and wrote one. Not elegant, but clean enough.
Actually, when I get to the office, I'll try to post it somewhere and send a link, if you don't already have an impl.
@gilligan, I'm with @davidchambers: slight hesitation, but interested.
Scott Sauyet
@CrossEye
Oct 30 2015 11:42
@niloy: I'm glad to see work in this direction. Our older lazy list extension was dropped for lack of attention, but I've always regretted that. It will take a while to consider the specifics.
Niloy Mondal
@niloy
Oct 30 2015 11:45
@CrossEye 👍
Raine Virta
@raine
Oct 30 2015 12:02

is there an issue open on these repl issues?

:point_up: October 17, 2015 2:37 PM
:point_up: September 11, 2015 4:13 PM

Scott Sauyet
@CrossEye
Oct 30 2015 14:04
@joneshf: transpose: http://bit.ly/20fPHXB
Scott Sauyet
@CrossEye
Oct 30 2015 14:14
@raine: can't replicate that first issue in Ramda console. Same (correct) behavior in 0.15, 0.16, 0.17
And 0.18.
Raine Virta
@raine
Oct 30 2015 14:14
ramda console?
Scott Sauyet
@CrossEye
Oct 30 2015 14:15
REPL. Sorry
One on docs site.
Raine Virta
@raine
Oct 30 2015 14:18
I can't reproduce in node repl either
so it's somehow related to node's repl module
Scott Sauyet
@CrossEye
Oct 30 2015 14:19
Forgot about the second issue. I still wonder if it had to / has to do with the implementation of is.
Any likelihood of multiple domains in play in replem?
Raine Virta
@raine
Oct 30 2015 14:21
~ ❯❯❯ node -e 'require("repl").start({})'
> var R = require('ramda');
undefined
> R.concat([1], [1])
TypeError: [1] does not have a method named "concat"
    at Object.<anonymous> (ramda/dist/ramda.js:7542:19)
    at Object.<anonymous> (ramda/dist/ramda.js:300:35)
    at Object.<anonymous> (ramda/dist/ramda.js:51:27)
    at Object.<anonymous> (ramda/dist/ramda.js:4880:23)
    at Object.<anonymous> (ramda/dist/ramda.js:300:35)
    at Object.concat (ramda/dist/ramda.js:51:27)
    at repl:1:3
    at REPLServer.defaultEval (repl.js:166:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
Hardy Jones
@joneshf
Oct 30 2015 14:22
@CrossEye jawesome!
@CrossEye now put it in an npm package :)
Scott Sauyet
@CrossEye
Oct 30 2015 14:29
I'm guessing that what's failing is this test in invoker: is(Function, target[method])
Raine Virta
@raine
Oct 30 2015 14:32
~ ❯❯❯ node -e 'require("repl").start({})'
> (function(){}) instanceof Function
true
> (function(){}).constructor === Function
true
Julien Goux
@jgoux
Oct 30 2015 14:39
Is it possible to do async call in reduce ?
I want to accumulate data from multiple api calls
Scott Sauyet
@CrossEye
Oct 30 2015 14:41
I think you want to reduce the result of an all invocation.
Raine Virta
@raine
Oct 30 2015 14:44
> R.is(Function, function() {})
true
> R.invoker(0, 'toString')(function(){})
TypeError: function (){} does not have a method named "toString"
> var target = function(){}
> target['toString']
[Function: toString]
how's this possible?
Scott Sauyet
@CrossEye
Oct 30 2015 14:46
No clue. What's your environment?
Raine Virta
@raine
Oct 30 2015 14:47
node v4.2.1
Andreas Köberle
@eskimoblood
Oct 30 2015 14:48
what should I do if I need a counter, as in the normal JS map, in map function?
Raine Virta
@raine
Oct 30 2015 14:48
R.addIndex
Andreas Köberle
@eskimoblood
Oct 30 2015 14:49
that was fast, thanks
Scott Sauyet
@CrossEye
Oct 30 2015 14:55
@raine: can duplicate this in replem. No time to investigate now. Can you post an issue?
Raine Virta
@raine
Oct 30 2015 15:03
I think @davidchambers had something on this
but it looks like that the function you pass to R.invoker from repl has a different Function at .constructor than ramda does when it does the check for is(Function)
target // function (){}
target.constructor === Function // false
(function() {}).constructor === Function // true
Raine Virta
@raine
Oct 30 2015 15:14

Not a bug. Modules and the REPL run in separate VM contexts. Each context has its own set of "root" objects (Object, String, Date, etc.). Look at e.g. isRegExp() in lib/util.js to see how we handle that:

https://github.com/nodejs/node-v0.x-archive/issues/1834#issuecomment-2312105

Julien Goux
@jgoux
Oct 30 2015 15:17
@CrossEye I want to make my requests one after another, and reduce the total of all the results
Julien Goux
@jgoux
Oct 30 2015 15:32
Even with Promise.all, there is something wrong with my syntax :p
    return pipe(
        splitEvery(chunkSize),
        map(geocodeChunk),
        Promise.all,
        then(concat)
    )(addresses)
geocodeChunk returns a promise
Denis Stoyanov
@xgrommx
Oct 30 2015 15:38
@jgoux Promise.all.bind(Promise)
Julien Goux
@jgoux
Oct 30 2015 15:39
@xgrommx Yes I change that but I think I have another issue because now it returns nothing lol
Denis Stoyanov
@xgrommx
Oct 30 2015 15:39
or R.bind(Promise.all)
Raine Virta
@raine
Oct 30 2015 15:42
@jgoux what are you expecting it to return?
concat takes two arguments, you're passing it only one, presumably
Martin Algesten
@algesten
Oct 30 2015 15:43
then(apply(concat))?
Raine Virta
@raine
Oct 30 2015 15:44
unnest maybe
Julien Goux
@jgoux
Oct 30 2015 15:44
@raine Yes it was unnest !
my bad !
David Chambers
@davidchambers
Oct 30 2015 17:35
@raine, see plaid/sanctuary#105 for the approach I used to remove instanceof checks from Sanctuary.
Raine Virta
@raine
Oct 30 2015 19:17
@davidchambers thanks
Raine Virta
@raine
Oct 30 2015 20:28
@davidchambers should Ramda do something about it as well?
David Chambers
@davidchambers
Oct 30 2015 20:29
Yes, I think so.
Raine Virta
@raine
Oct 30 2015 20:29
then we need an issue
David Chambers
@davidchambers
Oct 30 2015 20:30
We have ramda/ramda#1140.
Raine Virta
@raine
Oct 30 2015 20:30
great
Asaf
@asaf-romano
Oct 30 2015 20:38
@CrossEye / @davidchambers I think this may be related to your recent work on pipe/compose: ramda/ramda#1483
Raine Virta
@raine
Oct 30 2015 22:27
any nice solution to passing a dependency object like stdout stream three functions deep? you could define functions inside a closure that has the dependencies but then it's not easy to tell what the functions depend on in the context. then there's Reader but I haven't seen anyone use it
Scott Sauyet
@CrossEye
Oct 30 2015 22:40
@asaf-romano: I will try to look at it soon. I'm pretty swamped. If you have any ideas about the specific causes, I'd love to hear them.
David Chambers
@davidchambers
Oct 30 2015 23:11
How does one refer collectively to the a and the b in Either a b?
Hardy Jones
@joneshf
Oct 30 2015 23:17
type variables
David Chambers
@davidchambers
Oct 30 2015 23:20
True. But how would one refer collectively to String and Number in Either String Number? Types "inside" types, in other words.
Hardy Jones
@joneshf
Oct 30 2015 23:25
arguments
David Chambers
@davidchambers
Oct 30 2015 23:25
Okay, thanks!