These are chat archives for ramda/ramda

30th
Sep 2017
Mike Accomazzo
@accomazzo
Sep 30 2017 00:35
Any thoughts/opinions/experience on Immutable.js vs Ramda? Just found out about immutable, it's super fast, and is maintained by Facebook. Though from a quick look I don't see anything about the concepts of auto-currying and partial application, might not be as robust
Brad Compton (he/him)
@Bradcomp
Sep 30 2017 02:30
@accomazzo I think they can be used complementarily, rather than being direct competitors. You can keep your data in immutablejs data structures, and then utilize Ramda to operate on those structures. Ramda doesn't really provide any data structures, but it will dispatch it's map, concat, etc. to a structure that provides those methods. They seem to be a pretty good fit for one another, I have used them together in the past fairly seamlessly...
Lihai Ben-Haim
@lihaibh
Sep 30 2017 05:49
Can someone help me figure out why this code doesnt work? https://runkit.com/lihaibh/play-ramdajs
however:
hasPropThatIsString('a', {a:'s'})
this does work
Kurt Milam
@kurtmilam
Sep 30 2017 08:57
@lihaibh when you call the function like hasPropThatIsString('a' )( {a:'s'}), 'a' is passed into prop, which returns a function that is immediately passed into is( String ), which immediately returns false. Then, when you pass in ( {a:'s'} ), you're calling false( {a:'s'} ). Since false isn't a function, you get the error you're seeing.
When you call the function like hasPropThatIsString('a', {a:'s'}), both 'a' and {a:'s'} are passed into prop immediately, returning 's', which is then passed into is( String ).
This form works if you want to pass one argument at a time: o( o( is( String ) ) )( prop ) (REPL)
Kurt Milam
@kurtmilam
Sep 30 2017 09:04
My solution works because 'a' is passed into prop, which returns a function that is supplied as the second argument to the inner o, resulting in o( is( String ) )( prop( 'a' ) ), a function that is waiting for an argument like {a:'s'}.
Lihai Ben-Haim
@lihaibh
Sep 30 2017 10:14
@kurtmilam look at my example again: https://runkit.com/lihaibh/play-ramdajs
why hasPropThatNotNull works and propIsNull function doesnt?
I only added R.complement around propIsNull
Lihai Ben-Haim
@lihaibh
Sep 30 2017 10:29
by i way if i wrap my function with "curry" it works as well
const hasPropThatIsString = R.curry(R.pipe(R.prop, R.is(String)));
hasPropThatIsString('a')({a:'123'});
because it will expect more parameters until it fulfilled, but i thought all ramda function are automatically curried..
Kurt Milam
@kurtmilam
Sep 30 2017 10:34

This is the code I see when I follow your link:

var R = require('ramda');
const isPromise = R.both(R.is(Object), R.pipe(R.prop('then'), R.is(Function)));
const hasPropThatIsString = R.pipe(R.prop, R.is(String));
const hasPropAThatIsString = hasPropThatIsString('a');

hasPropThatIsString('a')({a:'s'})

You may need to save it if you've made some changes.

From the docs on pipe:

Note: The result of pipe is not automatically curried.

@lihaibh ^^
Lihai Ben-Haim
@lihaibh
Sep 30 2017 10:37
@kurtmilam go to master branch
i dont know they handle branches and versions here when u change the snippet
why the result of pipe not automatically curried?
Kurt Milam
@kurtmilam
Sep 30 2017 10:42
How is propIsNull not working?
Lihai Ben-Haim
@lihaibh
Sep 30 2017 10:42
without curry its not working
Kurt Milam
@kurtmilam
Sep 30 2017 10:43
It's not working for the same reason that hasPropThatIsString doesn't work if it's not curried.
I believe the result of pipe is not curried because that's how pipe usually works in most functional languages.
Lihai Ben-Haim
@lihaibh
Sep 30 2017 10:44
pipe is not automatically curried because sometimes u want to pipe functions?
as data
in what case
i mean a curried pipe wont be resolved until each interanl function in the sequence is resolved
unline not curried pipe that is resolved as you invoke it
corrent me if im wrong
Kurt Milam
@kurtmilam
Sep 30 2017 11:01
If by 'curried pipe' you mean R.curry( R.pipe ), I think curry only applies to the first invocation rather than to each internal function.
Kurt Milam
@kurtmilam
Sep 30 2017 11:21
@lihaibh pipe isn't curried by default because there are cases where you wish to pass a function to another function, for instance.
Kurt Milam
@kurtmilam
Sep 30 2017 11:38
This example is probably clearer and makes more sense.
Lihai Ben-Haim
@lihaibh
Sep 30 2017 11:42
whats the purpose of "are"?
check each element?
Kurt Milam
@kurtmilam
Sep 30 2017 11:44
Yes, are simply applies is to each element in a list.
Lihai Ben-Haim
@lihaibh
Sep 30 2017 11:44
ah nice
Kurt Milam
@kurtmilam
Sep 30 2017 11:44
The general idea is that you can build a function to pass into map or some other function that expects a function as an argument.
are is a contrived example to show how the fact that the result of pipe isn't curried makes that possible.
Lihai Ben-Haim
@lihaibh
Sep 30 2017 11:45
@kurtmilam this returns a function are( Number, data )
Kurt Milam
@kurtmilam
Sep 30 2017 11:46
yes, it has to be called like are( Number )( data )
Lihai Ben-Haim
@lihaibh
Sep 30 2017 11:48
I get it now thx
Kurt Milam
@kurtmilam
Sep 30 2017 11:49
You're welcome!
This filterByType example may be slightly more useful :)
Lihai Ben-Haim
@lihaibh
Sep 30 2017 12:28
nice
Florian Schrödl
@floscr
Sep 30 2017 17:00
Anybody know how I can get around the duplicate object spreading?
const hoursWorkedDay = ({ start, end, breaks }) => pipe(
  D => differenceInMinutes(end, start),
  D => reduce(subtract, D, breaks),
  D => divide(D, 60),
)({ start, end, breaks })
Julio Borja Barra
@juboba
Sep 30 2017 19:46
you can just remove it
oh
no, you can't
Kurt Milam
@kurtmilam
Sep 30 2017 20:40
@floscr is this alright? Or maybe this? Or this? Or this?
Rolf Strijdhorst
@rolfst
Sep 30 2017 20:47
@floscr how about this:
var a = moment(start);
var b = moment(end);
substract(a.diff(b, 'minutes'), breaks)
Kurt Milam
@kurtmilam
Sep 30 2017 20:49
And I'll plug date-fns if you're looking for a library. I think it's a better-written library than momentjs.
Kurt Milam
@kurtmilam
Sep 30 2017 21:09
OK, really the last one :D :
const [ s, e, b ] = [ 0, 600, [ 15, 15, 15 ] ]

const differenceInMinutes = flip( subtract )

const hoursWorkedDay =
  o( o( o( flip( divide )( 60 ) ) ) )
   ( o( o( reduce( subtract ) ) )
      ( differenceInMinutes )
   )

hoursWorkedDay( s )( e )( b )
// -> 9.25
Rolf Strijdhorst
@rolfst
Sep 30 2017 21:10
lol you are on a roll @kurtmilam
everything aside I still believe I would just use that date library. a lot less lines to care about
Kurt Milam
@kurtmilam
Sep 30 2017 21:11
@rolfst :+1: I probably would, as well. That last one is certainly not straightforward to decipher.
YarnBall
@yarnball
Sep 30 2017 23:18
Hi, Im doing a bit of an elaborate ramda R.pipe( groupBy( pipe( prop('type'), find(pipe(prop('level'), equals(1))), propOr('NoName', 'name'), ), ), map( pipe( pluck('type'), flatten, filter(pipe(prop('level'), gte(__, 2))), uniq, ), ), toPairs, map(zipObj(['name', 'typechild'])), )
However, it is only returning the "name" field in the "name" field on the equals(1) field, but I want it to return the whole object. Any ideas? Sample output commented below- https://goo.gl/3vE2nW