These are chat archives for ramda/ramda

27th
Jul 2016
Jigar Gosar
@jigargosar
Jul 27 2016 14:29
splitEvery will give me rows from a list. (am representing a 2d grid as list.) Is there a way to get columns from a list. Basically I am trying to rotate a 2D matrix. And according to http://stackoverflow.com/a/8664879/71858 that requires reversing the columns. I will gladly accept any other form of rotation algo, as long as I don't have to write for loops :D
may be some combination of transpose and zip might help, but can't figure out +90 -90 +180 deg rotation.
Jigar Gosar
@jigargosar
Jul 27 2016 14:38
Ok let me ask it another way, is there a way to make zip work with more than 2 arrays?
Tim Navrotskyy
@dypsilon
Jul 27 2016 14:41
Hi everyone, I have an object and some of its properties are Futures. Is there an easy way to convert it into a Future of the object?
Jigar Gosar
@jigargosar
Jul 27 2016 14:59
figured the solution out
var rotateRows = function (degrees) {
        var reverseRows = _.map(_.reverse);
        var rotateRight = _.compose(reverseRows, _.transpose);
        return _.apply(_.compose, _.repeat(rotateRight, (degrees / 90) | 0));
    };
Rob Halff
@rhalff
Jul 27 2016 20:03
how to do this better: isNaN(prop('body')({body: 1}))
so the object is the last argument to be applied, have it be the subject I guess.
I actually want to use Buffer.isBuffer, but the concept is the same.
Rob Halff
@rhalff
Jul 27 2016 20:10
ah, compose(isNaN, prop('body'))({body: 1}), weird, didn't seem to work before.
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:10
@rhalff I was about to give that exact solution
If it isn't working the same for Buffer.isBuffer, perhaps you need to bind the context?
Rob Halff
@rhalff
Jul 27 2016 20:12
@Bradcomp I probably will, I'm testing it in the browser now, so need to go back to node :)
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:13
:-D
Rob Halff
@rhalff
Jul 27 2016 20:14
I had this first: compose(Buffer.isBuffer, tap(console.log), assocPath(['body'])) which fails, compose(Buffer.isBuffer, tap(console.log), prop('body')) does work.
ok, assocPath is plain wrong.
which happens when I pretend to know the functionality from the top of my head.
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:16
Yeah, that will give you back an object
If {body: 1}, {}, and undefined are all possible inputs, you could consider using path instead of prop, or using a defaultTo in front. prop will fail if you pass it null or undefined
@ram-bot
prop('body', null)
ram-bot
@ram-bot
Jul 27 2016 20:19
Cannot read property 'body' of null
Rob Halff
@rhalff
Jul 27 2016 20:20
I do not see the usefulness of having two functions for those btw.
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:21
path will let you grab nested props
Rob Halff
@rhalff
Jul 27 2016 20:22
that should be the default :)
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:22
@ram-bot
path(['body', 'a'], {body: {a: 1}})
ram-bot
@ram-bot
Jul 27 2016 20:22
1
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:22
@ram-bot
path(['body', 'a'], {body: null})
ram-bot
@ram-bot
Jul 27 2016 20:22
undefined
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:23
@ram-bot
path(['body', 'a'], undefined)
ram-bot
@ram-bot
Jul 27 2016 20:23
undefined
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:23
Sorry for the spam
Rob Halff
@rhalff
Jul 27 2016 20:24
I like the flexibility of the get function in lodash: https://lodash.com/docs#get
what are the opinions here about lodash.fp ?
which mainly flips the arguments, so object is last.
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:26
Lodash get looks nice, although I don't like that it casts strings to arrays...
I haven't really spent any time with lodash fp tbh
I guess just flipping arguments around and supporting currying and partial application is not fully functional programming.
yet that's the level I'm still at :-)
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:37
It looks good to me. The argument order and auto-currying are some of the biggest gains I get from using Ramda over loash / underscore, so there's that. I like that Ramda was built from the ground up to support the style of FP that it is good for. It seems like most of the decisions around the library are fairly principled, and thus its behavior is very predictable (with the arguable exception of the comparison operators :ducks:)
Lodash FP may have all the same advantages, as I've said I haven't really used it, but I also have seen no reason to make me want to switch.
Rob Halff
@rhalff
Jul 27 2016 20:39
no need to switch really also, you can just import single lodash functions if there is a need.
Brad Compton (he/him)
@Bradcomp
Jul 27 2016 20:42
That's true.
Paul
@pauloliver
Jul 27 2016 21:50

@Bradcomp

Lodash get looks nice, although I don't like that it casts strings to arrays...

Are you talking about lodash's internal castPath and stringToPath functions?

Brad Compton (he/him)
@Bradcomp
Jul 27 2016 21:51

@dypsilon

Hi everyone, I have an object and some of its properties are Futures. Is there an easy way to convert it into a Future of the object?

If you have some control over the structure of your data you could get to a point where R.traverse could work for you. Otherwise, maybe Fantasy do could be of use

@pauloliver I didn't look at the internals, but probably.

is model.id the name of your key, or is it a nested property? when you use an array, those two are unambiguous.

['model.id'] and ['model', 'id']
Paul
@pauloliver
Jul 27 2016 21:54
Ah didn't think about that...