These are chat archives for ramda/ramda

27th
Sep 2016
Syaiful Bahri
@syaiful6
Sep 27 2016 12:50
just to inform try rambda on the site error with message sanctuary not defined
Jigar Gosar
@jigargosar
Sep 27 2016 12:50
var applySpec2 = _.curry(function(spec, propNames, obj){       
  var result = _.applySpec(spec)(obj);      
  return _.merge(result , _.pick(propNames, obj))
});
since this is a very common usage for transforming a model to view model I wrote this generic function. Can this be made better, please share your views.

basically I need to wirte


{
   derivedProp: function(model){return model.a+model.b}
   propName:_.prop("propName")
...
}

for every prop I need to pick from model apart from other derived props I have to write some verbose " propName:_.prop('propName') " code this is an attempt to avoid typing, is there a better way to do this?

Jigar Gosar
@jigargosar
Sep 27 2016 12:56
I am not able to find a simple function composition to achieve this, so the code looks very verbose. Please help!
LeonineKing1199
@LeonineKing1199
Sep 27 2016 16:47
Would Ramda's pick maybe do what you want? I'm not entirely sure what you're going after. There's also evolve.
Keith Alexander
@kwijibo
Sep 27 2016 19:17
I think it looks good @jigargosar
es6 version is a bit shorter:
const applySpec2 = (spec, props) => 
    obj => 
        R.merge(R.applySpec(spec, obj), R.pick(props, obj))
Keith Alexander
@kwijibo
Sep 27 2016 19:25
is there a name for this combinator? f => g => h => x => f(g(x), h(x))
Denis Stoyanov
@xgrommx
Sep 27 2016 20:05
This message was deleted
@kwijibo this is converge) in ramda
@kwijibo yourOp = f => g => h => x => converge(f, [g, h])(x)
@kwijibo or lift yourOp = f => g => h => x => lift(f)(g, h)(x)
@kwijibo also f(...sequence(always, [g, h])(x))
Denis Stoyanov
@xgrommx
Sep 27 2016 20:37
@kwijibo I realize also yourOp = B(B(S))(B)
Keith Alexander
@kwijibo
Sep 27 2016 20:37
:)
very neat
Denis Stoyanov
@xgrommx
Sep 27 2016 20:38
@kwijibo this is just liftA2
Keith Alexander
@kwijibo
Sep 27 2016 20:40
i forgot that R.lift treats functions as applicatives
Denis Stoyanov
@xgrommx
Sep 27 2016 20:40
@kwijibo I love combinators)) Brainstorm for create pointfree version =)
Keith Alexander
@kwijibo
Sep 27 2016 20:42
wow that's a lot
I find the trouble is other programmers (not least myself in the future), knowing/remembering what pattern the name of the combinator represents, in order to be able to work out what is going on in the code
Denis Stoyanov
@xgrommx
Sep 27 2016 20:46
@kwijibo basic idea like in lego just combinate combinators
@kwijibo you shouldn't have free variables in combinator.
Denis Stoyanov
@xgrommx
Sep 27 2016 20:53
@kwijibo
let x = \f -> f(\x y -> x)(\x y z -> x z $ y z)(\x y -> x)

let s = x (x x)
let k = x x x
let b = s (k s) k

let lift = b(b(s))(b)

let i = s k k
let w = s s (s k)
let w'' = b (b w)
let c = s (b b s) (k k)
let q = c b
let join = w;
let bind' = w'' b
let bind = w'' q
let fish = b (b (b w)) (c (b b b))
let fish' = c fish

-- comonad
let extract = k i
let duplicate = w b
let extend = b (b duplicate) b
@kwijibo only first combinator has lambdas
@xgrommx exists some theorem. If we have basis for combinators then we can implement infinity combinators just via combination their.