These are chat archives for ramda/ramda

13th
Mar 2017
Denis Stoyanov
@xgrommx
Mar 13 2017 00:07
common case with object should be in last line
Johnny Hauser
@m59peacemaker
Mar 13 2017 00:08
Right.
But it is ideal if types were just more rational.
I imagine there's not much that can be done about that without abandoning JS altogether.
James Forbes
@JAForbes
Mar 13 2017 01:56
Array.isArray?
Alexis De La Torre
@Alexis-De-La-Torre
Mar 13 2017 04:05

so, iam trying to wrap my head around Futures...

const test = pipe(
  x => Future((reject, resolve) => setTimeout(() => resolve(x), 2000)),
  chain(concat('hello '))
)

test('world!').fork(error, log)

Shouldn't this be working?
when i run it i get TypeError: f(...).fork is not a function
but if i do

log(test('world!'))

I get Future { fork: [Function: bound ] }

Rick Medina
@rickmed
Mar 13 2017 04:31
chain monad with another monad, otherwise map over it
@Alexis-De-La-Torre
Keith Alexander
@kwijibo
Mar 13 2017 11:52
ie
const test = pipe(
 Future.of,
 map(concat('hello '))
)

@dtipson recently pointed out in fantasyland/fantasy-land that if you want to do setTimeout, you can do

x => new Future((reject, resolve) => setTimeout(resolve, 1000, x))

instead of

x => Future((reject, resolve) => setTimeout(() => resolve(x), 2000))
Drew
@dtipson
Mar 13 2017 13:19
less useful in FP, but any # of additional parameters are allowed after the delay: setTimeout will call the callback with all of them as positional arguments. e.g. setTimeout((...args)=>console.log(...args), 1000, 1, 2, 3, 4)-> logs 1 2 3 4 (obviously console.log defeats the purpose of not needing the extra function, but illustrates what's going on)
Gavin Chen
@Gavinchen92
Mar 13 2017 13:37
hello everyone!
Stefano Vozza
@svozza
Mar 13 2017 15:28
hello :)
Rod Lalama
@RodLalama_twitter
Mar 13 2017 15:39
hey
Brad Compton (he/him)
@Bradcomp
Mar 13 2017 16:17
:wave:
Karl Heinz Pongratz
@karlponti_twitter
Mar 13 2017 19:30

Hi all, I'm new here, this is my first Ramda question. I am wondering how to test a javascript object with Ramda if any of its property is true. For example:

const obj = {a:  false, b:  true, c:  false};

// In Javascript (nice but becomes ugly with long property names or many properties)
const isAny = (obj.a  ||  obj.b  ||  obj.c);

// In Ramda
const isAny = R.any( (x)  =>  x  ===  true)(R.values(obj));

Is there a better way to do this in Ramda? For example how could I shorten the predicate function or maybe there is even a better way to do this.
Thanks

Ryan Zeigler
@rzeigler
Mar 13 2017 19:33
you could replace your lambda on the last line with R.equal(true)
I think If I were going to do this I would probably write
const anyTrue = R.compose(R.any(R.equals(true)), R.values);
so as to make it reuseable
@karlponti_twitter
Karl Heinz Pongratz
@karlponti_twitter
Mar 13 2017 19:37
Thanks @rzeigler, that looks very nice!
@rzeigler works like a charm. Composition is something I haven't mastered yet.
Piet Vandeput
@piet-v
Mar 13 2017 20:07
Anyone know a clean way to get rid of the state params in this example?
const stateMapper = (state) => {
  return {
    isAuthorized: isAuthorizedState(state),
    username: username(state)
  };
};
so it can be used like this:
someFunction({
    isAuthorized: isAuthorizedState,
    username: username
  })
Kurt Milam
@kurtmilam
Mar 13 2017 20:28
@piet-v I believe applySpec will do the trick http://ramdajs.com/docs/#applySpec .
Piet Vandeput
@piet-v
Mar 13 2017 20:29
ah cool, thx!
Kurt Milam
@kurtmilam
Mar 13 2017 20:30
:thumbsup:
Brad Compton (he/him)
@Bradcomp
Mar 13 2017 20:31
R.evolve
Piet Vandeput
@piet-v
Mar 13 2017 20:51
mmm seems both R.applySpec and R.evolve don't fill my use case?
the resulting function seems to expect 2 parameters but I wanna pass state only
R.applySpec({
      isAuthorized: isAuthorizedState,
      username: username
    })
can't use R.evolve either cause it copies all the properties on state but I only want to transform the ones I supply and drop the others
plus the keys in the transformation object don't match the keys in the keys in the state object, so that only leaves R.applySpec
Piet Vandeput
@piet-v
Mar 13 2017 21:15
fixed it:
R.applySpec({
      isAuthorized: isAuthorizedState,
      username: username
    })(R.__, undefined);
Lucas Schejtman
@lucasschejtman
Mar 13 2017 21:44
@piet-v doesn't this work for you ? https://goo.gl/CXeR1K
Piet Vandeput
@piet-v
Mar 13 2017 21:45
fn expects 2 params for me so it won't execute till it receives 2 params :/
Lucas Schejtman
@lucasschejtman
Mar 13 2017 21:47
oh, does it make sense to keep it ?
Piet Vandeput
@piet-v
Mar 13 2017 21:48
only need the first param, passing undefined as second param solves my problem but weird situation nonetheless
Piet Vandeput
@piet-v
Mar 13 2017 21:54
k fixed it, nasty pass-by-reference situation
Lucas Schejtman
@lucasschejtman
Mar 13 2017 21:55
(Y)
Piet Vandeput
@piet-v
Mar 13 2017 21:55
or not :D
gulp failed when I removed the (R.__, undefined) so ofc it still passed rofl
Piet Vandeput
@piet-v
Mar 13 2017 22:04
ok, just double checked in REPL
seems like R.applySpec needs the same amount of parameters as the specs inside the specObject
so if one of the specFunctions expects 3 params applySpec also expects 3 params
In my situation I'm using reselect selectors which apparently expect 2 params which explains a whole lot :laughing: