These are chat archives for ramda/ramda

9th
Jun 2016
Ricardo Pallas
@RPallas92
Jun 09 2016 13:19
What’s the best way to use Ramda with Angular 1.x without import it as a global variable?
GÁBOR Áron Zsolt
@ashnur
Jun 09 2016 15:11
There is no way to use Angular and still call it "best" in any situation :(
LeonineKing1199
@LeonineKing1199
Jun 09 2016 15:23
ha!
What a slam on Angular
James Grayling
@jamesgrayling
Jun 09 2016 15:23
haha
Use Webpack and import with destructuring?
This message was deleted
import { map, compose } from ‘ramda’
Though that’s a lot of overhead just to use Angular’s dependency injections
Jakub Korzeniowski
@kujon
Jun 09 2016 16:35
What is the rationale behind R.toString quoting a value which is already a string? R.toString('abc'); //=> '"abc"'
Brad Compton (he/him)
@Bradcomp
Jun 09 2016 16:37

From the docs:

eval'ing the output should result in a value equivalent to the input value.

I ran into that too, it caused me some grief until I figured out what was going on.
Jakub Korzeniowski
@kujon
Jun 09 2016 16:43

it doesn't always follow that rule though:

var a = {};
var b = {};

b.foo = a;
a.foo = b;

toString(a); // > {"foo": <Circular>}

So wondering what's the rationale behind this rule in the first place

Brad Compton (he/him)
@Bradcomp
Jun 09 2016 16:44
Well, is there a way they could follow the rule in that case though?
LeonineKing1199
@LeonineKing1199
Jun 09 2016 16:44
You almost broke JS w/ that code, btw :laughing:
Jakub Korzeniowski
@kujon
Jun 09 2016 16:45
@Bradcomp there isn't.
@LeonineKing1199 if not worse :D
My point is more: if you can't always follow that rule, I'd like to know the rationale behind why it was introduced
LeonineKing1199
@LeonineKing1199
Jun 09 2016 16:46
That's a good point, actually
Scott Sauyet
@CrossEye
Jun 09 2016 19:23
1
Vladimir Kapustin
@kapooostin
Jun 09 2016 20:42
Why aren’t these two functions equivalent? The first works fine but the second one throws 'f is not a function‘ error:
//1
var updateHasTitle  = R.map( item => R.compose(
    R.ifElse(
      R.has( 'items' ),
      R.over( R.lensProp( 'items' ), updateHasTitle ),
      R.identity
    ),
    R.ifElse(
      R.pathSatisfies(
        R.either( R.isNil, R.isEmpty ),
        [ 'content', 'title' ]
      ),
      R.assocPath( [ 'content', 'hasTitle' ], false ),
      R.assocPath( [ 'content', 'hasTitle' ], true )
    )
  )( item )
);

//2
var updateHasTitle  = R.map( R.compose(
    R.ifElse(
      R.has( 'items' ),
      R.over( R.lensProp( 'items' ), updateHasTitle ),
      R.identity
    ),
    R.ifElse(
      R.pathSatisfies(
        R.either( R.isNil, R.isEmpty ),
        [ 'content', 'title' ]
      ),
      R.assocPath( [ 'content', 'hasTitle' ], false ),
      R.assocPath( [ 'content', 'hasTitle' ], true )
    )
  )
);
Brad Compton (he/him)
@Bradcomp
Jun 09 2016 20:53

@kapooostin You can't do explicit points-free recursion in Javascript like that. In the second example:
R.over( R.lensProp( 'items' ), updateHasTitle ),

updateHasTitle has not been defined yet, so it evaluates to undefined. Inthe first example updatHasTitle doesn't get evaluated until the mapping function is run, so it works

Vladimir Kapustin
@kapooostin
Jun 09 2016 21:20
@Bradcomp thank you!
I need only one level of recursion so I guess I could rewrite it.
Brad Compton (he/him)
@Bradcomp
Jun 09 2016 21:24
Is there a built in for this?
var fs = [inc, dec]
var vals = [1,2]

zipWith(apply, fs, map(of, vals))    //[2, 1]