These are chat archives for ramda/ramda

7th
Apr 2016
Walle Cyril
@GrosSacASac
Apr 07 2016 01:30
D.vr is not just a standard object, it has properties that are defined with Object.defineProperty( with getters and a setters. I need a strict equivalent, ie use an assignement to call the proper getters when needed
Brad Compton (he/him)
@Bradcomp
Apr 07 2016 01:35

@GrosSacASac Would Object.assign help?

It uses the getters and setters:

The Object.assign() method only copies enumerable and own properties from a source object to a target object. It uses [[Get]] on the source and [[Put]] on the target, so it will invoke getters and setters.

Of course, that still won't work if you're worried about overwriting existing data
Walle Cyril
@GrosSacASac
Apr 07 2016 01:48
I tried Object.assign but it s not the same. what I need here would be more Object.assignDeep becuase Object.assign goes only 1 level down. Maybe I can use Object.assign instead of the innermost loop
Walle Cyril
@GrosSacASac
Apr 07 2016 01:55
```
    let scopeName,
        variableName,
        DVrScopeName,
        commentsDataScopeName;

    for (scopeName of Object.keys(commentsData)){
        if (!D.vr[scopeName]) {
            D.vr[scopeName] = {};
        }
        DVrScopeName = D.vr[scopeName];
        commentsDataScopeName = commentsData[scopeName]
        Object.assign(DVrScopeName, commentsDataScopeName);
        /* same as  
        for (variableName of Object.keys(commentsData[scopeName])){
            D.vr[scopeName][variableName] = commentsData[scopeName][variableName];
        } */
    }
can I simplify more ?
Brad Compton (he/him)
@Bradcomp
Apr 07 2016 02:03
This message was deleted
Aldwin Vlasblom
@Avaq
Apr 07 2016 12:37

Anyone happen to have a way to get from:

[
  [1, 2],
  [1, 2, 3],
  [1]
]

to:

[
  [1, 1, 1],
  [2, 2],
  [3]
]
Kind of rotating the data
I feel like I've seen it before in this room, but I have no idea what the context was anymore.
Julien Goux
@jgoux
Apr 07 2016 12:40
Risto Stevcev
@Risto-Stevcev
Apr 07 2016 12:42
@ram-bot R.transpose([[1,2], [1,2,3], [1]])
ram-bot
@ram-bot
Apr 07 2016 12:42
[ [ 1, 1, 1 ], [ 2, 2 ], [ 3 ] ]
Aldwin Vlasblom
@Avaq
Apr 07 2016 12:43
I knew it! Awesome! Perfect! Thanks! :D
Walle Cyril
@GrosSacASac
Apr 07 2016 12:43
Ramda is so good
As much as es2015 took inspiration in python, coffeescript, I wish new es2017 syntax will be inspired by ramda and co
Risto Stevcev
@Risto-Stevcev
Apr 07 2016 12:46
@GrosSacASac es7 async/await should replace co eventually
I think they might also be introducing Observables
Though I wish they introduced something like a hindley milner type system and typeclasses. That kind of type system can be backwards compatible if it treats a function parameter as an "any" type by default
Julien Goux
@jgoux
Apr 07 2016 13:04
lool
Julien Goux
@jgoux
Apr 07 2016 13:31
hindley milner type system and typeclasses yes plz! :fire: :fire: :fire:
Lewis
@6ewis
Apr 07 2016 13:46
@Bradcomp thank you so very much. I don't understand what objectUpdater is doing on your code example. You always seem to have the answer, you have a knack for that style of coding
let objectUpdater = R.compose(R.map(serializeNullValue), updateEntityType)
//Does R.map map over the values of the object returned by updateEntityType?
Lewis
@6ewis
Apr 07 2016 13:53
Yes it does, I answer my own question. @Bradcomp thanks that's smart
Aldwin Vlasblom
@Avaq
Apr 07 2016 14:25
Is this something better generalized by another pattern?
//kReduce :: Chain m => (b, a -> m b) -> m b -> [a] -> m b
const kReduce = f => m => xs => xs.reduce((m, x) => m.chain(acc => f(acc, x)), m);
The reason I'm asking is because it seems very useful, but I haven't seen it anywhere else, leading me to conclude that there must be some more widely employed way to solve the same problem.
Lewis
@6ewis
Apr 07 2016 14:32
@Avaq what does it do?
let arrayOfAttributeNames  = [null, null, null, null];
let verifyIfAllNil = (acc, next) => {
  return ((acc === true) && (next === null)) ? true : false;
}
R.reduce(verifyIfNil, true, arrayOfAttributeNames);
is there a better way do to this?
Aldwin Vlasblom
@Avaq
Apr 07 2016 14:35
@ram-bot R.all(R.isNil) ( [null, null, null, null] )
ram-bot
@ram-bot
Apr 07 2016 14:35
true
Lewis
@6ewis
Apr 07 2016 14:35
damn
6ewis This message was deleted
Lewis
@6ewis
Apr 07 2016 14:36
@Avaq thanks
Julien Goux
@jgoux
Apr 07 2016 15:13
not related to ramda but does anyone use proxyquire ?
Is it possible to stub a function from the same module passed to proxyquire ?
const a = () => {}
const b = () => {}
const c = () => R.pipe(a, b)
I'd like to test c but without calling the real a and b
Sorry I'm a noob at testing, but I want to improve ! :smile:
Tobias Pflug
@gilligan
Apr 07 2016 15:40
@jgoux we banned proxyquite from our codebase
@jgoux we even added a test such that linting fails if additional uses of proxyquire are introduced
Julien Goux
@jgoux
Apr 07 2016 15:42
wow
xD
why ?
and what do you use instead ?
LeonineKing1199
@LeonineKing1199
Apr 07 2016 15:42
Quick question, can a curried version of zipWith be used in a transducer function?
Like, I have an array that I'm map'ing over and then I'm calling zipWith immeidiately after
Tobias Pflug
@gilligan
Apr 07 2016 15:44
@jgoux the fact you reach for proxyquire implies that you want to change internal behaviour - which is undesirable
instead you should use dependency injection - i.e pass in the dependencies
Julien Goux
@jgoux
Apr 07 2016 15:45
@gilligan I use proxyquire to mock things like database or ssh
Tobias Pflug
@gilligan
Apr 07 2016 15:46
yes, that does not change the fact that you should be passing in a function that carries out an IO operation instead of having the unit that you want to test access the Database and fiddle with proxyquire to overwrite that
when using proxyquire to mock away internals of your unit, your test depends on implementation details
Julien Goux
@jgoux
Apr 07 2016 15:51
I'm not sure I follow
this is the piece of code I want to test
@gilligan Could you point me what's wrong with it ? ^^
At first I wanted to test only main as it was the only "public" function
LeonineKing1199
@LeonineKing1199
Apr 07 2016 15:58

I tried this and it didn't work T_T

let a = [0, 1, 2, 3, 4, 5, 6, 7]
let b = [7, 6, 5, 4, 3, 2, 1, 0]

let transducer = R.compose(R.zipWith((x, y) => { return x * y; }, b), R.map(R.add(2)))
R.transduce(transducer, R.flip(R.append), [], a)

Getting....
xf.@@transducer/step is not a function

Aldwin Vlasblom
@Avaq
Apr 07 2016 16:00
@LeonineKing1199 I don't think zip and family can act like transducers. Usually the documentation would state that explicitly.
LeonineKing1199
@LeonineKing1199
Apr 07 2016 16:01
Nuuuuuuuuu!!!!
Tobias Pflug
@gilligan
Apr 07 2016 16:02
@jgoux sorry, busy now.. it boils down to not passing in dbConnection but a function that will return the result of a database operation - the real code will carry out actual db interaction - the test code will just pass in a function that returns the result
Julien Goux
@jgoux
Apr 07 2016 16:07
this is why for testing "main", I'd need to stub getPatient + assertPatient + getLastDemandesEditables no ?
so I don't care about their implementation ?
Then I can test one level deeper with for example getPatient
Aldwin Vlasblom
@Avaq
Apr 07 2016 16:12
@jgoux What gilligan is trying to say is that you means of stubbing is flawed. You're trying to stub by hacking your implementation, whereas you could stub by "injecting" the things you'd want to stub. So for example main would take getPatient, assertPatient and getLastDemandesEditables as arguments. Then from your test you could just call main with stubbed versions of those dependencies.
Julien Goux
@jgoux
Apr 07 2016 16:14
oh ok :D
But the function signature would be...weird
so it would be better to always inject modules + internal function explicitly ?
I can always export a partially applied function :p
Risto Stevcev
@Risto-Stevcev
Apr 07 2016 17:15
I think it's generally good practice bc it leads to less highly coupled code, so you can decompose it into unit tests, which would make you less reliant on e2e tests and less likely to have merge conflicts when different devs work on different parts of the frontend, and easier to debug
Julien Goux
@jgoux
Apr 07 2016 17:36
yes I'm trying to adapt my code right now to inject all the dependencies ^^
But I'm a little afraid of monads in JS without a type system
LeonineKing1199
@LeonineKing1199
Apr 07 2016 17:41

Don't do monads in JS, do monads in C++!!!!

http://bartoszmilewski.com/2011/07/11/monads-in-c/

This guy is honestly one of my favorite bloggers XD

LeonineKing1199
@LeonineKing1199
Apr 07 2016 17:51

I love that guy :)

Bringing functional programming concepts to a language people think only supports OOP. Seriously, thank God for std::function and closure types.

David Chambers
@davidchambers
Apr 07 2016 18:49

But I'm a little afraid of monads in JS without a type system

My too, @jgoux, which is why I use a (run-time) type system. ;)

Julien Goux
@jgoux
Apr 07 2016 18:49
Which one ?
sanctuary-def ?
I think I'll try to use one too
David Chambers
@davidchambers
Apr 07 2016 18:50
Yeah. Either directly or indirectly via Sanctuary.
It has caught bugs in production code with 100% test coverage!
Julien Goux
@jgoux
Apr 07 2016 18:50
what do you mean by directly or indirectly ?
David Chambers
@davidchambers
Apr 07 2016 18:51
I don't necessary use sanctuary-def in every project, but because Sanctuary uses it I get the benefits whenever I use Sanctuary functions and types.
A mistake I often make is mixing monads.
I'll have a value of type Either String String and will want to convert the Right to an integer.
I might do something like R.chain(S.parseInt(10), e), forgetting that I'm in Either context rather than Maybe context.
Either#chain will complain, though.
Julien Goux
@jgoux
Apr 07 2016 18:53
yes this is why I don't want to use a lot of them right now, because of the stack it creates, without type checking it's a nightmare
I don't imagine the look of a code using something like : Reader + Future + Either + Maybe
David Chambers
@davidchambers
Apr 07 2016 18:54
Try evaluating this expression on one of the REPLs on the Sanctuary website:
R.chain(S.parseInt(10), S.Right('42'))
Julien Goux
@jgoux
Apr 07 2016 18:55
nice ^^
David Chambers
@davidchambers
Apr 07 2016 18:55
@ram-bot
R.chain(S.parseInt(10), S.Right('42'))
ram-bot
@ram-bot
Apr 07 2016 18:55
TypeError: ‘Either#chain’ is expected to return a value of type (Either a c); returned Just(42)
David Chambers
@davidchambers
Apr 07 2016 18:55
It makes it obvious what I got wrong and how to correct it.
Julien Goux
@jgoux
Apr 07 2016 18:55
Yes indeed
I didn't know I can use R.chain to chain monads
xD
I always do something like : S.pipe([a(), F.chain(b), F.chain(c)])
cleaner with R.chain !
(I used the chain from fluture)
David Chambers
@davidchambers
Apr 07 2016 18:59
Nice.
Julien Goux
@jgoux
Apr 07 2016 19:03
@davidchambers Do you use sanctuary-def on your own functions ?
David Chambers
@davidchambers
Apr 07 2016 19:04
I certainly do. Check out generate, easily the nicest build script I've written to date.
Julien Goux
@jgoux
Apr 07 2016 19:05
Will check thanks !
what is the second argument of def ?
David Chambers
@davidchambers
Apr 07 2016 19:05
This gives me warm fuzzies:
pipe([at(2),
      maybeToEither('Missing command-line argument'),
      map(lift2(pair, I, I)),
      map(over(lensIndex(0), version)),
      map(over(lensIndex(1), readme)),
      chain(ifElse(all(isRight),
                   pipe([rights, Right]),
                   pipe([lefts, join('\n'), Left]))),
      map(over(lensIndex(0), wrap(' <small>v', '</small>'))),
      map(apply(replace(/(?=<[/]h1>)/))),
      map(toDocument),
      chain(writeFile('index.html')),
      either(failure, success)],
     process.argv);
The second argument to def indicates the type-class constraints.
Julien Goux
@jgoux
Apr 07 2016 19:13
@davidchambers I don't understand the $.env initialization. You register all the types you will check ?
what if I make a type Point and I don't put it in the $.env ?
or is this just a shortcut for accessing $.Point ?
Drew
@dtipson
Apr 07 2016 20:23
const X = curry(function(f, g, x, y) { return f(g(x,y)); });
const isFirstOrNone = X(gte(0), lastIndexOf);
const GFirstOrNone = isFirstOrNone('G');
GFirstOrNone('G456546');//-> true
GFirstOrNone('5G456546');//-> false
Is there any common Combinator or pattern I'm missing a cleaner abstraction for implementing something like the above (basically, the rightmost function needs to get two arguments, preferrably one by one, before it's result can be passed to the leftmost one, so just compose(gte(0), lastIndexOf) wouldn't quite work)?
Stefano Vozza
@svozza
Apr 07 2016 20:39
node.js 4.3 support finally added to aws lambda:
https://forums.aws.amazon.com/ann.jspa?annID=3672
Martin Broder
@mrtnbroder
Apr 07 2016 21:19

does someone have an idea how I can make this... more functional? also my structure doesn't match 100% what I want (included).

I was wondering if I could use R.lensIndex with R.lensPath but R.lensPath(path) creates objects instead of an arry.

http://goo.gl/TEqZ2H

with R.set
Martin Broder
@mrtnbroder
Apr 07 2016 21:37
@dtipson
const isFirstOrNone = R.pipe(R.head, R.equals('G'));
isFirstOrNone('G456546');//-> true
isFirstOrNone('5G456546');//-> false
not exactly an answer to your question, but this does the same job I guess.
maybe take a look at R.partialRight
David Chambers
@davidchambers
Apr 07 2016 22:18

I don't understand the $.env initialization. You register all the types you will check ?

I agree that this is somewhat confusing, @jgoux. The reason it's necessary to define an environment (a list of types) is to support type variables. In order to determine whether [x, y, z] is a valid value of type $.Array(a), we need to know all the possible values of a – in other words, all the types we'd like to consider.

For a type such as $.Array($.Number) we don't need knowledge of the environment.