These are chat archives for ramda/ramda

Sep 2018
Konstantin Dichev
Sep 05 2018 12:58
        cell => includesWest(cell) && !includesNorth(cell),
        always([[1, 0], [1, 0]])
hey guys is there R func I can use to pass cell to both includesWest and includesNorth and get the result. Been roaming the docs for a while now
Karthik Iyengar
Sep 05 2018 13:31

How do I write a function that operates over a result of an existing function? For instance:

const multiplyPathResultByFive = compose(multiply(5), path))

Since path has an arity more than one, the above won’t work if invoked like so:
multiplyPathResultByFive([“a”])({ a: 5 })

Sep 05 2018 14:53
How can I transform a nested array [[a, 1], [b, 2], [c, 3]] into [[ a, b, c ], [1, 2, 3]]
Sep 05 2018 15:05
nevermind R.transpose does it
Brad Compton (he/him)
Sep 05 2018 15:23
@kdichev I am not sure what you need exactly, but the first line in your array could use both and complement like this:
both(includesWest, complement(includesNorth))(cell);
@karthikiyengar For a simple case like that, you could manually curry the result - curryN(2, compose(multiply(5), path)), or just pass both parameters in at once. The issue that you're running into is that compose doesn't curry the resultant function.
For more complicated scenarios you could check out converge and useWith
Karthik Iyengar
Sep 05 2018 15:47
@Bradcomp - Ah, that’s smart. Thanks.
Pedro Ávila
Sep 05 2018 22:59

So, I'm learning FP, I really like the idea of writing code without (or at least, avoiding) statements, by only using expressions, no variable declarations...

Am I wrong to think like that? Sometimes it feels really hard to write code like that. Also, I'm having a hard time trying to be less repetitive, below is an example of that:

(msg, model) => {
  const id = view(nextIDLens) (model)
  return pipe(
    over (flashcardsByIdLens) ( assoc (id) (createFlashcard(id)) ),
    over (flashcardsUILens) ( assoc(id) (createFlashcardUI()) ),
    over (flashcardListLens) (prepend (id)),
    over (nextIDLens) (inc),
  ) (model)

If I didn't declare id on the top, the code would be a mess, and I'm also repeating it everywhere.

BTW, msg is not being used but I receive it anyway, it is the equivalent of an redux action, this function acts as an reducer (although I'm not using redux/react in this app), model is the state of the app.

I could provide a sample of the model if needed, and also the lenses and createFlashcard/UI functions.

Would love any feedback on this, thanks in advance!

Pedro Ávila
Sep 05 2018 23:06
Here's a working sample on the REPL:
Asad Saeeduddin
Sep 05 2018 23:10
@avilapedro You should be aware that what we have as a const statement in JS would still be an expression in other languages
i.e. a let expression
we just don't have expression scoped variable bindings in JS
so I don't think it's a good idea to avoid making sensible variables just because JS doesn't have let binding