These are chat archives for ramda/ramda

21st
Jul 2017
James Forbes
@JAForbes
Jul 21 2017 04:54
@rickmed :smile:
Almost didn't put that in :D
Julien Goux
@jgoux
Jul 21 2017 07:05
Hello all
Is there a function in ramda to call a function from an object ?
possibly somethink like : f -> args -> object
which results in object.f(args)
Carl Barrdahl
@carlbarrdahl
Jul 21 2017 07:07
Julien Goux
@jgoux
Jul 21 2017 07:07
it's to simplify some handlers I have in react + preventDefault
@carlbarrdahl Seems to be what I want :D
thanks !
Carl Barrdahl
@carlbarrdahl
Jul 21 2017 07:26
np! can you show me an example of what you're trying to to just out of curiosity?
Gabe Johnson
@gabejohnson
Jul 21 2017 12:43
@Ben52 I know it's super late, but I think the function you wanted was zipWith. It acts like map2 in Elm
Joey Figaro
@joeyfigaro
Jul 21 2017 15:29
hey folks
Michael Rosata
@mrosata
Jul 21 2017 15:30
@joeyfigaro Hey Joe
Joey Figaro
@joeyfigaro
Jul 21 2017 15:30
Hey there @mrosata - been a while since I’ve been around. :)
Michael Rosata
@mrosata
Jul 21 2017 15:31
:)
Joey Figaro
@joeyfigaro
Jul 21 2017 15:31
Was wondering if anyone could point out how I might clean up these guys with something like compose or pipe? http://joeysharesthings.com/0B0B1V0V0W3G
Michael Rosata
@mrosata
Jul 21 2017 15:31
they always come back
Joey Figaro
@joeyfigaro
Jul 21 2017 15:31
lol
I tried this, which failed: http://joeysharesthings.com/1C0o1B0H3B1e
but I’d like a cleaner return.
Michael Rosata
@mrosata
Jul 21 2017 15:33
well, they just happen to be 2 functions that get ran at the same time right? They don't depend on each others input/output right?
Joey Figaro
@joeyfigaro
Jul 21 2017 15:33
That’s correct
Michael Rosata
@mrosata
Jul 21 2017 15:35
compose or pipe implies that one depends on some input and then the other depends on that return value. I could be better just to call the functions seperately
or if they take the same input you could juxt([ winListener, beginListener ])
Joey Figaro
@joeyfigaro
Jul 21 2017 15:40
And I suppose the inputs here would be the callbacks I’m setting up there - and those also have the same arguments, but provide different arguments to the function they return: http://joeysharesthings.com/2E0m3a0Q2V2m
Koalabz
@koalabz
Jul 21 2017 16:10

Hi everyone,
Simple question :

const obj = {}
const getObj = fn => ({ get: fn })
const defineProp = R.curry( (property, key, value) => Object.defineProperty(obj, key, property) )
const freeze = R.pipe(getObj, defineProp)
freeze(() => 'my frozen value')('label', obj) //> work like expected 
console.log(obj.label) // > 'my frozen value'

// but
freeze(() => 'my frozen value', 'label', obj) //> doesn't work

I know that pipe works with unary functions but how can i do to retrieve a curried freeze function with 3 parameters ?

Michael Rosata
@mrosata
Jul 21 2017 16:26

@koalabz you could do:

const freeze = useWith(defineProp, [getObj])

at https://goo.gl/ZktJDs

Koalabz
@koalabz
Jul 21 2017 16:35
@mrosata thanks :smile: perfect! Pretty new to Ramda and didn't use useWithbefore.
Michael Rosata
@mrosata
Jul 21 2017 16:36
@koalabz np, good luck :)
Austin Wei
@awei01
Jul 21 2017 17:25
Hi, still trying to better grok ramda. I have a gist here: https://gist.github.com/awei01/9319094cbad3c07d0ff65dc356d13cb5
2 questions: 1) How come I need to add () to invoke the function in my e.g. _resolveRuleResult. 2) Is there a better way to refactor my gist?
Kurt Milam
@kurtmilam
Jul 21 2017 21:33
@awei01
  1. because pipe always has to be called twice, first with a list of function and second with the input.
Try this, although I haven't used pipeP or worked with Ramda + Promises:
  return (
    pipeP( partial( checkRule
                  , [ rules[ key ]
                    , data
                    , value
                    ]
                  )
         , ifElse( identity
                 , always( accumulator )
                 , always( key ) 
                 )
         )
         ( Promise.resolve() )
  )
And this:
  return (
    ifElse( identity
          , always( accumulator )
          , partial( callback, [ accumulator, key ] )
          )
          ( accumulator )
  )
Kurt Milam
@kurtmilam
Jul 21 2017 21:41
What does identity do?
That code looks a little suspect.
Kurt Milam
@kurtmilam
Jul 21 2017 21:47
If that's R.identity, you should know that if accumulator is equal to '', 0, null, undefined or false, the else branch will execute.
Here's a rewrite of the second using unless:
    unless( identity
          , partial( callback, [ accumulator, key ] )
          )
          ( accumulator )
Same principle for the ifElse in the first block.