These are chat archives for ramda/ramda

19th
Apr 2016
Julien Goux
@jgoux
Apr 19 2016 08:01
Hello
Is there a way to define union-types with sanctuary-def ?
I'd really like to be able to have union-types + pseudo pattern matching ^^
David Chambers
@davidchambers
Apr 19 2016 08:08
There's $.EnumType, but that doesn't support parameterized types. Pattern matching would be very nice indeed.
Ricardo Pallas
@RPallas92
Apr 19 2016 15:42

Is it possible to reject a data.Task with a function inside a map with a condition

For example: I retrieve a Task(Error User) and I want to check the password task.map(checkPassword), and reject it, if the password isn’t correct

Jose Luis
@josete89
Apr 19 2016 16:56
@RPallas92 I think you can return false inside task.map(checkPassword)
Juan Soto
@sotojuan
Apr 19 2016 17:33
What would I use if I havevar a = {a: 1,....}; var b = {} and I want to loop through keys and values of a and copy them to b?
Chet Harrison
@ChetHarrison
Apr 19 2016 17:35
Can anyone tell me why I am getting an array of null on this one
const divideBy = R.lift( R.divide );
console.log( divideBy( 4, 2 ) ); // [null]
Arnaud Bertrand
@ArnaudBertrand
Apr 19 2016 17:37
@sotojuan if you just want to copy there is clone
Juan Soto
@sotojuan
Apr 19 2016 17:37
Ah what if Iw ant to copy only some? I'm doing pick and then doing the copying with the picked elements
Arnaud Bertrand
@ArnaudBertrand
Apr 19 2016 17:37
@ChetHarrison I think you expect lift to use list of values and apply the function on each of those values (divideBy ( [4], [2] ) will produce [2]
Chet Harrison
@ChetHarrison
Apr 19 2016 17:38
ah right you are
Arnaud Bertrand
@ArnaudBertrand
Apr 19 2016 17:38
@sotojuan look at evolve ?
Juan Soto
@sotojuan
Apr 19 2016 17:41
I'll look but I'll also just say what I want: I have an object with a lot of keys, but I want only some keys. BUT a couple of those keys also need to be renamed
I have it working with forEach but I was curious if there's a side-effect free way
Arnaud Bertrand
@ArnaudBertrand
Apr 19 2016 17:43
pickBy look similar to what you want?
I'm far from being an expert in ramda so maybe someone will come with a better solution :)
Brad Compton (he/him)
@Bradcomp
Apr 19 2016 17:56
There's a method in the cookbook to rename keys of an object. You could compose that with pick to first pick the desired keys and then rename the ones you want?
Juan Soto
@sotojuan
Apr 19 2016 18:28
ill give it a try
thanks!
Aldwin Vlasblom
@Avaq
Apr 19 2016 18:50
@RPallas92 You can use chain to determine which branch the next task is going to be in:
const checkPassword = password => password === '123456' ? Task.of('secret sauce') : Task.reject('guess again')
task.chain(checkPassword)
Chet Harrison
@ChetHarrison
Apr 19 2016 20:07

I can't believe I am still banging my head against this wall. I have code that works in the REPL and not in my tests. In the REPL

const 
    NCMath = {
      divide : R.lift( R.divide ),
    },

    amountArray = R.props( [ 'amount' ] ),

    minorsInMajorArray = R.props( [ 'minorsInMajor' ] ),

    // getMajorAmount :: Obj -> Number
    getMajorAmount =
        NCMath.divide( amountArray , minorsInMajorArray ),

    arg = {
        major : 'a liter',
        majors : 'liters',
        minor : 'a centiliter',
        minors : 'centiliters',
        minorsInMajor : 100,
        amount : 100
    };

console.log( [
  amountArray( arg ),
  minorsInMajorArray( arg ),
  getMajorAmount( arg )
] );

gets me [[100],[100],1] which is what I want.

In my tests ...

// getMajorAmount :: Obj -> Number
    getMajorAmount = x => {
        NCUtil.tap( x );
        NCUtil.tap( amountArray( x ) );
        NCUtil.tap( minorsInMajorArray( x ) );
        const out = NCMath.divide( amountArray , minorsInMajorArray )(x);
        NCUtil.tap( out );
        return out;
    },

gets me

log: {
  "minorsInMajor": 100,
  "amount": 100
}

log: [
  100
]

log: [
  100
]
   X getMajorAmount
     TypeError: 'NaN' is not a function (evaluating 'NCMath.divide(amountArray, minorsInMajorArray)(x)') in file:///Users/chetharrison/projects/nimble-chef/dev/es5/app/util/metrics.js (line 247) (1)

getMajorAmount is supposed to be just

getMajorAmount = NCMath.divide( amountArray , minorsInMajorArray )

I just wanted to log it out

Vladimir Starkov
@iamstarkov
Apr 19 2016 20:34
hey
can we update R.pipe to take Array[Function]?
it's pretty annoying to not have trailing coma while you are debugging R.pipe with R.tap(console.log.bind(console))
Vladimir Starkov
@iamstarkov
Apr 19 2016 20:41
so, i have to use R.identity while debuggin the code, like this:
// this will be broken if i will put tap(log) in the end of pipe
const log = R.tap(console.log.bind())

// thats fine
R.pipe(
  fn1,
  log,
  fn2
)

// move log to the end and it will be broken
R.pipe(
  fn1,
  fn2
  log,
)
so i have to add R.identity to the end to not break pipe while debuggin
const id = R.identity
R.pipe(
  fn1,
  fn2,
  log,
  id
)
this will never be broken while debuggin
// pipe :: Array[Function]
R.pipe([
  fn1,
  fn2,
  log,
])
what do you think?
Arnaud Bertrand
@ArnaudBertrand
Apr 19 2016 20:53
you could use the spread operator on your array
Raine Virta
@raine
Apr 19 2016 21:02
@iamstarkov does https://www.npmjs.com/package/treis help
Chet Harrison
@ChetHarrison
Apr 19 2016 21:10

I guess this would be the most compact version

getMajorAmount = R.lift( R.divide )( 
        R.props( [ 'amount' ] ), 
        R.props( [ 'minorsInMajor' ] 
    ) )( {
        minorsInMajor : 100,
        amount : 100
    } )

it works in the REPL and when I call that same code from a Jasmine test I get Error: define: 'NaN' is not a function

Jonathan Curran
@joncfoo
Apr 19 2016 21:35
what is a good way to represent the following in JS?: data FieldState = Set Bool | NotSet
also wondering if there is any faux pattern matching available to be able to match the three states
Vladimir Starkov
@iamstarkov
Apr 19 2016 22:17
@raine treis is good, but has nothing to do with javascript not forgiving coma after the last argument