These are chat archives for ramda/ramda

5th
May 2016
Vladimir Starkov
@iamstarkov
May 05 2016 00:37
is anybody interesting in type checking/contracting/assering your libraries written in point-free/data-flow manner, then i wrote small contracting library, which i'm using myself in side-projects
https://github.com/iamstarkov/neat-contract
its working great with both sync and async data-flow
Screen Shot 2016-05-05 at 02.38.01.png
Screen Shot 2016-05-05 at 02.38.09.png
also working pretty okaish for complex structures like arrays
Screen Shot 2016-05-05 at 02.38.14.png
i was looking for smth like this (simple and very interopable), but failed, so i invented it for my own needs
so far pretty good
if i missed smth valuable in functional nodejs npm ecosystem pls tell me
also pls tell me if im doing anything wrong
Vladimir Starkov
@iamstarkov
May 05 2016 00:57
Sorry for wall of text. Was not really wanted to promote, but rather share my excitement about new possibilities of contracting and seeking for any kind of feedback
Brad Compton (he/him)
@Bradcomp
May 05 2016 01:05
Neat!
David Langford
@That-David-Guy
May 05 2016 01:35
When would one use R.assoc vs R.set? I've read the docs but can't see when they would return different results
@ram-bot
var cLens = R.lensProp('c');
[
  R.assoc('c', 3, {a: 1, b: 2}),
  R.set(cLens, 3, {a: 1, b: 2})
 ]
ram-bot
@ram-bot
May 05 2016 01:35
[ { a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 } ]
Scott Sauyet
@CrossEye
May 05 2016 01:40
assoc is the older functions, quite arguably simpler -- as it doesn't involve the creation of the lens before using it -- but much less flexible function. The lens functions such as set came later. @davidchambers has been suggesting for quite a while that we remove all the ones that overlap with the lenses. He may be right, but it still doesn't quite sit right with me.
@jonahx: Yes, that looks similar to mine. It's simpler, but doesn't allow for TCO. Some day that will actually matter, but it really doesn't as of yet.
Gleb Bahmutov
@bahmutov
May 05 2016 02:28
Hey everyone, I like ram-bot so much, I wanted to quickly write something that actually gives you Ramda code to compute the desired output from the given input.
I called it "Rambo" and put it on Github rambo - it can solve simple cases using brute-force, and I will be expanding it to cover more R functions.
David Langford
@That-David-Guy
May 05 2016 02:45
Thanks @CrossEye . I think I would prefer the R.assoc as I don't need to create the lens. But no biggie either way.
Jonah
@jonahx
May 05 2016 04:34
@CrossEye Thanks for the clarification about TCO. For fun, I’ve come up with one more, even less performant, but perhaps conceptually even simpler. And I suspect it could be trimmed down even a tad more:
var perm = arr => repeat(arr, arr.length).reduce(xprod).map(flatten)
                  .filter(x => uniq(x).length == x.length)
Constantin Dumitrescu
@dumconstantin
May 05 2016 12:50
This message was deleted
Constantin Dumitrescu
@dumconstantin
May 05 2016 12:57

Hi all, I'm working on a wrapper over Ramda functions and I have a question about Ramda's internals, how can I figure out that a function returned by calling a Ramda function is the final value and not a Ramda curry wrapper?. Example:

function foo() { }
let result = R.prop('a', { a: fn }); 
R.contains(result.name,  ['f1', 'f2', 'f3']) // false, it must be the final value

let result = R.prop('a'); 
R.contains(result.name, ['f1', 'f2', 'f3']) // true, it must be a Ramda wrapper

The problem with the above is that, if the user declares instead of foo a fn named "f1" then the check no longer applies. Also, curryN(https://github.com/ramda/ramda/blob/master/src/internal/_curryN.js) returns an anonymous function which I can't identify by name. There are no prototype methods attached to Ramda wrappers which I could use to do the test so atm I'm considering to test using f1.toString() === result.toString(), but this seems quite ugly. Any thoughts would be appreciated!

David Chambers
@davidchambers
May 05 2016 15:46
Inspect the length property. ;)
Constantin Dumitrescu
@dumconstantin
May 05 2016 16:00
but all functions have a length prop... does that help when trying to distinguish a Ramda curry wrapper from a regular function?
David Chambers
@davidchambers
May 05 2016 16:52
@ram-bot
R.prop.length
ram-bot
@ram-bot
May 05 2016 16:52
2
David Chambers
@davidchambers
May 05 2016 16:53
If you apply R.prop to two arguments you'll get the result; if you apply it to fewer than two arguments you'll get back a partially applied function.
Constantin Dumitrescu
@dumconstantin
May 05 2016 16:54
yup, so I'm trying to figure out if what I get in return is a partially applied function or a function as the final value
in the example above R.prop('a', { a: fn }) will get back a function foo e.g. how can I distinguish this function foo from the partial applied function in R.prop('a')
I'm using a wrapper over Ramda functions and evaluating results inside the wrapper, I need to return either the final value or another wrapper over the partial applied function....
its working, but I don't know the edge cases of other functions from Ramda besides those in the const ramdaWrappers declaration...
Brad Compton (he/him)
@Bradcomp
May 05 2016 17:10
R.pick
David Chambers
@davidchambers
May 05 2016 17:12
Is fn a Ramda function here, @dumconstantin?
let result = fn.apply(null, args)
Constantin Dumitrescu
@dumconstantin
May 05 2016 18:26
@davidchambers, yes
David Chambers
@davidchambers
May 05 2016 18:30
In that case, @dumconstantin, if args.length < fn.length, result will be a partially applied function.
Constantin Dumitrescu
@dumconstantin
May 05 2016 18:32
Indeed, but i need the evaluate the ''' result
ow, i think I get what you are saying
So before applying the fn I should count the number of arguments and if its less than the fn's the i'm sure it will return a partial aplication
David Chambers
@davidchambers
May 05 2016 18:35
The order in which you do the two things is not important but yes, that's what I'm suggesting. :)
Constantin Dumitrescu
@dumconstantin
May 05 2016 18:35
@davidchambers, pure genius :) thank you very much, do you forsee any issues with that?
David Chambers
@davidchambers
May 05 2016 18:35
No. Ramda functions are good about reporting their arity "correctly".
Constantin Dumitrescu
@dumconstantin
May 05 2016 18:37
cool, i'll remove the extra code and do the above and see if it passes the tests, great! Thanks!
David Chambers
@davidchambers
May 05 2016 18:37
Cool. Let me know if it works!
Chet Harrison
@ChetHarrison
May 05 2016 21:10
I guess concat in v18 works on pairs do you know function to cat all the returns into one string?
// renderRecipe :: Obj -> String
    renderRecipe = R.converge(
        R.concat( '' ),
        [
            renderTitle,
            renderIntro,
            renderServings,
            renderFoods,
            renderTasks
        ]
    ),
currently I'm getting the first 2
Brad Compton (he/him)
@Bradcomp
May 05 2016 21:12
Would unapply(reduce(concat, '')) work as your converging function?
Scott Sauyet
@CrossEye
May 05 2016 21:13
Not quite sure what you're doing @ChetHarrison. Are you looking for join?
Chet Harrison
@ChetHarrison
May 05 2016 21:14
well I though join was going to solve this but I got an error so let me explain
each of those functions in the converge array take an Object pullout a property and slap it in a string with some markup and returns that string
so all I really want to do is put all those returned strings in one big string
Brad Compton (he/him)
@Bradcomp
May 05 2016 21:16
I think unapply will help you out. It will take the arguments passed in to your converging function and turn them into an array
Chet Harrison
@ChetHarrison
May 05 2016 21:17
ahh yesser thats exactly what i need thanks @Bradcomp
Scott Sauyet
@CrossEye
May 05 2016 21:17
Looks like a combination of juxt and join to me. But I can't easily test on my phone.
Brad Compton (he/him)
@Bradcomp
May 05 2016 21:17
so you could probably do converge(unapply(join('')), [...])
Chet Harrison
@ChetHarrison
May 05 2016 21:17
roger that thanks gents