These are chat archives for ramda/ramda

1st
Jul 2015
Raine Virta
@raine
Jul 01 2015 01:05
at last, time to sleep
Hardy Jones
@joneshf
Jul 01 2015 01:11
@svozza the good thing about van Laarhoven lenses is that you don't have to wait for ramda
Hardy Jones
@joneshf
Jul 01 2015 01:20
You can define your lenses now, and they'll work now with R.pipe and in the future with R.pipe after ramda starts using van Laarhoven lenses.
Stefano Vozza
@svozza
Jul 01 2015 01:49
oh yeah, wasn't there some van Laarhoven lens JS library that someone mentioned a few days ago
Scott Christopher
@scott-christopher
Jul 01 2015 01:50
Stefano Vozza
@svozza
Jul 01 2015 01:51
yeah, think that was it
right time for bed, i'll be dreaming of evolving lenses
Hardy Jones
@joneshf
Jul 01 2015 02:27
Or, if you don't want the added dependency, you can implement it in a few lines.
I haven't looked at the implementation of drboolean's but something like this should work:
var objLens = R.curry(function(prop, f, obj) {
  return R.map(R.assoc(prop, R.__, obj), f(obj[prop]));
}
Hardy Jones
@joneshf
Jul 01 2015 02:50
and for getters and setters:
function Const(x) {
  if (!(this instanceof Const)) return new Const(x);
  this.runConst = x;
  this.map = R.const(Const(x));
}
function Id(x) {
  if (!(this instanceof Id)) return new Id(x);
  this.runId = x;
  this.map = R.compose(Id, R.call(R.__, x));
}
var get = R.curry(function(lens, x) {
  return lens(Const, x).runConst;
}
var over = R.curry(function(lens, f, x) {
  return lens(R.compose(Id, f), x).runId;
}
var set = R.curry(function(lens, y, x) {
  return over(lens, R.always(y), x);
}
so 22 lines for lens impl...
or better yet...
var set = R.compose(R.flip(over), R.always);
Hardy Jones
@joneshf
Jul 01 2015 02:56
Gives 20 lines exactly.
eh, that last line isn't right
Hardy Jones
@joneshf
Jul 01 2015 03:03
var set = R.flip(R.compose(R.flip(over), R.always));
though there's probably some free theorem that can clean that up
ilazarte
@ilazarte
Jul 01 2015 04:45
I have a function which accepts 1 parameter
I want it to always be invoked with the same parameter
duh nm partial
:)
David Chambers
@davidchambers
Jul 01 2015 04:59
I smell side effects (otherwise you could simply write var y = f(x); and use y).
Stefano Vozza
@svozza
Jul 01 2015 08:50
Thanks @joneshf !
Raine Virta
@raine
Jul 01 2015 09:57
@davidchambers not if you want to have the function as a value
Asaf
@asaf-romano
Jul 01 2015 20:03
Could it be there is no wrapper around Math.pow?