These are chat archives for ramda/ramda

6th
Sep 2018
Pedro Ávila
@avilapedro
Sep 06 2018 00:36
hmm, makes sense, in fact I've had an experience with Power Query which has the let in expression.
Pedro Ávila
@avilapedro
Sep 06 2018 01:21
Unfortunately JS syntax isn't very pleasant (from my perspective) with its blocks {} and return statement.
Jesús Gómez
@jgomo3
Sep 06 2018 14:09
Hello. Probably a FAQ again, but have not definitive answer. For the Question: Does Ramda support lazy evaluation or Python like generators? The answer would be a NO, or I'm missing something?
Jesús Gómez
@jgomo3
Sep 06 2018 14:25
mmm. I think the Javascripts generators are the thing to use.
Jesús Gómez
@jgomo3
Sep 06 2018 14:54
So, how to 'takeWhile' from a Javascript Generator
?
Galileo Sanchez
@galileopy
Sep 06 2018 14:59
this should work, right? the Maybe doc says is FL compatible
const a = Maybe.Just(1)
const b = Maybe.Just(1)
const addMaybe = lift(add)
c = addMaybe(a, b)
// Maybe.Just(3)
Pedro Ávila
@avilapedro
Sep 06 2018 17:28

@masaeedu I made it! Now I have a single expression and don't repeat id everywhere:

(msg, model) =>
  pipe(
    ap(
      pipe (
        compose(of, view (nextIDLens)),
        ap ([
          ap (assoc) (createFlashcard),
          flip (assoc) (createFlashcardUI()),
          prepend,
        ]),
        zip ([
          over (flashcardsByIdLens),
          over (flashcardsUILens),
          over (flashcardListLens)
        ]),
        map(apply(call)),
        apply(compose),
      )
    ) (identity),
    over (nextIDLens) (inc),
  ) (model)

REPL: https://goo.gl/nYo6k3

Is that reasonable? Or complete madness?

Asad Saeeduddin
@masaeedu
Sep 06 2018 18:01
seems much more complicated and hard to understand in my opinion @avilapedro, but YMMV
Pedro Ávila
@avilapedro
Sep 06 2018 18:06
@masaeedu really thank you for your opinion! I googled about "YMMV" and looks like it stands for "Your Mileage May Vary", but I'm not sure about what it means, maybe something like "it depends on your perspective" ?
Asad Saeeduddin
@masaeedu
Sep 06 2018 18:07
@avilapedro Yes, exactly. I may think it's worse, but another person may think it's a big improvement
Pedro Ávila
@avilapedro
Sep 06 2018 18:07
got it!
Thank you for taking the time.
Asad Saeeduddin
@masaeedu
Sep 06 2018 18:08
no worries
i haven't used it myself, but an alternate approach might be to try and define something like let or where as utility functions. E.g.
const where = x => f => f(x)

const result = ({ x, y }) => x + y) |> where({ x: 1, y: 2 })

console.log(result) // => 3
Pedro Ávila
@avilapedro
Sep 06 2018 18:16
So, |> is a pipe operator? That where function is essentially the same as Ramda's applyTo right?
Asad Saeeduddin
@masaeedu
Sep 06 2018 18:17
yes, x |> f |> g is g(f(x))
also yeah, where = applyTo
Pedro Ávila
@avilapedro
Sep 06 2018 18:19
But why is that useful? I don't understand the use case
Asad Saeeduddin
@masaeedu
Sep 06 2018 18:20
it just avoids the const statement and lets you create expression scoped variables
Pedro Ávila
@avilapedro
Sep 06 2018 18:20
inside the object literals right?
Asad Saeeduddin
@masaeedu
Sep 06 2018 18:20
yes
personally I don't mind just using const, but if you do want to keep everything as an expression there's still ways to do it
Pedro Ávila
@avilapedro
Sep 06 2018 18:21
hmmmmm, makes sense, that looks cool, I may play with it.
Thanks for sharing