These are chat archives for ramda/ramda

14th
Oct 2016
Bravi
@Bravilogy
Oct 14 2016 13:50
Hi guys. I'm trying to create a tic tac toe game. I have an array consisting of 'X' and 'O' -['x', 'o', 'x', 'x', 'x', 'o', 'o' ....]
the array indexes correspond to the cells on the board. So what I want to do, is to check if any of these combinations of indexes have the same characters:
const combos = [
   [0, 1, 2],
   [3, 4, 5]
   [6, 7, 8]
   //... and so on
]
so I tried to create the following functions:
const findMatch = R.pipe(R.match(/x{3}|o{3}/gi), R.length); // so this needs either 'xxx' or 'ooo' to pass and it returns a length number, which I can convert to boolean

// and then to loop over the combos, I was trying to do something like this:
const checker = R.map(
   R.pipe(
      combo => findMatch(R.join('', R.pickAll(combo)(board)))
   )
);
where board is an array of 'x' and 'o'
but R.pickAll returns an object, instead of an array so I cannot use R.join. any suggestions?
LeonineKing1199
@LeonineKing1199
Oct 14 2016 14:59
Instead of pickAll, could you use something like? * Not tested!
const extractSubArray = (arrayData, arrayIds) => {
  assert(Array.isArray(arrayData) && Array.isArray(arrayIds));
  return arrayIds.map(idx => arrayData[idx]);
};
That way, you're extracting the indices out out of board pointed to by the values of the combo array
Bravi
@Bravilogy
Oct 14 2016 15:00
hmm I'll give it a try
thanks
LeonineKing1199
@LeonineKing1199
Oct 14 2016 15:27
@Bravilogy Btw, thank you, you've given me the first ever use-case of a permutation iterator in JavaScript! There's fancy iterators in other libraries and permutation is one of 'em so I've been seeing if I can port them to Node. I didn't have a solid use-case for permutation iterator until you posted. So thanks!
Bravi
@Bravilogy
Oct 14 2016 15:39
hah :D no problem. Anyway, I solved it!
gotta love ramda
and FP in general
so thank you too
LeonineKing1199
@LeonineKing1199
Oct 14 2016 15:41
Sorry, almost went on a rant about iterators and iterables XD
Adam Recvlohe
@arecvlohe
Oct 14 2016 15:53
Can anyone tell me why I get a r.apply is not a function on this code I ran in the Ramda REPL:
const arr = [
  { s3Key: 'someKey' }
]

const noStuff = [
  {}
]

var hasImage = R.ifElse(
  R.pipe(R.head, R.has('s3Key')),
  R.head,
  R.of({})
);
hasImage(arr)
hasImage(noStuff)
Brad Compton (he/him)
@Bradcomp
Oct 14 2016 15:55
@ram-bot
R.of({})
ram-bot
@ram-bot
Oct 14 2016 15:55
[ {} ]
Ben Farr
@JaminFarr
Oct 14 2016 15:55
Switch the R.of({}) to R.always({})
Brad Compton (he/him)
@Bradcomp
Oct 14 2016 15:55
:point_up:
Adam Recvlohe
@arecvlohe
Oct 14 2016 15:55
Oh okay, got it
What does the ram-bot do?
Just curious
Brad Compton (he/him)
@Bradcomp
Oct 14 2016 15:56
It evaluates your expressions
Adam Recvlohe
@arecvlohe
Oct 14 2016 15:56
Oh nice!
Brad Compton (he/him)
@Bradcomp
Oct 14 2016 15:57
It can also give you helpful links
R.of
Adam Recvlohe
@arecvlohe
Oct 14 2016 15:57
I guess i was confused, I thought R.of returned whatever you put in it, but instead return array of that
Oh that’s pretty cool
Thanks @Bradcomp and @JaminFarr !
LeonineKing1199
@LeonineKing1199
Oct 14 2016 17:26
Ha, is flip supposed to be based on Haskell's cardinal combinator?
I finally saw the signature: (a -> b -> c) -> b -> a -> c
Also, the irony is, I thought to myself, I'd never actually wind up using the psi combinator and here I am, literally finding a perfectly valid use for it
LeonineKing1199
@LeonineKing1199
Oct 14 2016 17:31
Lol guess you can't discredit something early :P
But shouldn't a variadic version of flip reverse the entire argument signature and not just the first two parameters?