These are chat archives for ramda/ramda

13th
Apr 2017
Denis Stoyanov
@xgrommx
Apr 13 2017 07:32
@Bradcomp ap(flip(assoc('id')), path(['children', 0, 'id']))(request)
Bravi
@Bravilogy
Apr 13 2017 09:51
hey guys, what's the difference between a Free Monad and a normal Functor? As I understand, Free Monad basically saves the value passed to it and then composes functions by using map only to call the composed function with that value in the end, isn't that correct?
Denis Stoyanov
@xgrommx
Apr 13 2017 10:08
@Bravilogy Free monad like a Fix for types
Bravi
@Bravilogy
Apr 13 2017 10:27
maybe I'm not catching the whole point of it but it kinda looks like a complication of things
Tushar Mathur
@tusharmath
Apr 13 2017 14:15
Is there a logic for by vs with in the ramda functions?
Its confusing sometimes :( why is with and not by ?
for eg: uniqBy and uniqWith I always get confused which one does what
Brad Compton (he/him)
@Bradcomp
Apr 13 2017 14:50
@tusharmath in general with functions take a (a, a) -> Boolean function to compare two elements. by functions take an a -> b function to transform a single element before comparison
Robert Mennell
@skatcat31
Apr 13 2017 16:45
@tusharmath You confirm something with logic. Yout transform something by changing it is how I try to remember it
Michael Rosata
@mrosata
Apr 13 2017 16:50
I like that @skatcat31. I try to remember it by thinking that I'm looking at a thing "by itself" or "with something else"
Denis Stoyanov
@xgrommx
Apr 13 2017 18:09
what is your solution for Given an array of integers, find the largest product yielded from three of the integers
var unsortedArray = [-10, 7, 29, 30, 5, -10, -70];

computeProduct(unsortedArray); // 21000
Robert Mennell
@skatcat31
Apr 13 2017 18:18
@xgrommx are you asking for algorithm or code?
Denis Stoyanov
@xgrommx
Apr 13 2017 18:20
in ramda combinators :smile:
Robert Mennell
@skatcat31
Apr 13 2017 18:39
Okay I'm missing some logic and there is some repeated of the missing logic.. BUUUt.... this should be hte roadmap, right?
pipe(
sort,
ifElse(
  converge(
    gt,
    [
      pipe(
        // ... function for least 2 and largest in array
      ),
      pipe(
        // ... function for 
      )
    ]
  ),
  pipe(
    // ... function for least 2 and largest in array(2 neg, 2 positive)
  ),
  pipe(
    // ... function for greatest 3(all positive)
  )
)
Denis Stoyanov
@xgrommx
Apr 13 2017 18:40
result should be {"21000": [30, -10, -70]}
@skatcat31 you need sublists by 3 from [-10, 7, 29, 30, 5, -10, -70]
Robert Mennell
@skatcat31
Apr 13 2017 18:43
I'm having problems trying to find ramda complimentors for that sublist though...
like if I had a way to grab that sublist I'd pass it to pipe, then pipe to some function that would multiply them all togethor
Denis Stoyanov
@xgrommx
Apr 13 2017 18:44
yes, because u need monadic filter for list :smile:
@ram-bot
var filterM = curry((of, p) => reduceRight((x, a) => lift(flg => flg ? prepend(x) : identity)(p(x), a), of([])))

compose(
  ap(flip(objOf), product),
  xs => xs.reduceRight(maxBy(product)),
  filter(compose(equals(3), length)),
  filterM(of, always([true, false]))
)([-10, 7, 29, 30, 5, -10, -70])
ramdabot is dead?)
Robert Mennell
@skatcat31
Apr 13 2017 18:45
has been since yesterday
Denis Stoyanov
@xgrommx
Apr 13 2017 18:47
Robert Mennell
@skatcat31
Apr 13 2017 18:48
already copy pasta into repl XD
Denis Stoyanov
@xgrommx
Apr 13 2017 18:48
@skatcat31 try it filterM(of, always([true, false]))([1,2,3]) :smile:
Robert Mennell
@skatcat31
Apr 13 2017 18:50
christ that gets big fast...
Denis Stoyanov
@xgrommx
Apr 13 2017 18:51
@skatcat31 interesting applicative effect?)
@skatcat31 another interesting compose(sequence(of), repeat(__, 2))([1,2,3]) try to change 2 in repeat
Robert Mennell
@skatcat31
Apr 13 2017 18:54
the problem I see with that one is it repeats values
Denis Stoyanov
@xgrommx
Apr 13 2017 18:55
@skatcat31 this is replicateM
Robert Mennell
@skatcat31
Apr 13 2017 18:59
Hmm... maybe when I'm a lot more comfortable with FP beyond flow control I can give this a lot better attempts... Right now I'm kind of in that "Using FP in production" but not at the "theoreticals solved with FP" level... sadly XD
Robert Mennell
@skatcat31
Apr 13 2017 19:03
:+1:
Denis Stoyanov
@xgrommx
Apr 13 2017 19:06
@skatcat31 try it compose(map(flatten), traverse(of, x => [[x], []]))([1,2,3]) ;)
@skatcat31 or compose(map(flatten), traverse(of, x => [x, []]))([1,2,3])
Robert Mennell
@skatcat31
Apr 13 2017 19:07
was going ot ask why x was in a list...
Denis Stoyanov
@xgrommx
Apr 13 2017 19:08
@skatcat31 compose(map(filter(Boolean)), traverse(of, x => [x, undefined]))([1,2,3])
@skatcat31 applicative effect =)
Robert Mennell
@skatcat31
Apr 13 2017 19:08
rewriting it in pipe for myself: pipe( traverse(of, x => [ x, [] ] ) , map( flatten ) )
Denis Stoyanov
@xgrommx
Apr 13 2017 19:10

@skatcat31 as u know traverse is like a map but has applicative effect. For example

compose(traverse(of, x => [x, undefined]))([1,2,3])
[[1, 2, 3], [1, 2, undefined], [1, undefined, 3], [1, undefined, undefined], [undefined, 2, 3], [undefined, 2, undefined], [undefined, undefined, 3], [undefined, undefined, undefined]]

All internal containers has 3 elements (from functor law) and external applicative effect

filterM (\a -> Just (a > 1)) [1..10] => Just [2,3,4,5,6,7,8,9,10]
Robert Mennell
@skatcat31
Apr 13 2017 19:14
traverse seems like it'd make the most sense to me. Also why undefined instead of false?
Denis Stoyanov
@xgrommx
Apr 13 2017 19:15
it doesn't matter
Robert Mennell
@skatcat31
Apr 13 2017 19:16
oh wait... duh Boolean... hah.. I'm good
Denis Stoyanov
@xgrommx
Apr 13 2017 19:17
traverse (\x -> [x,x*x]) [1..3] => [[1,2,3],[1,2,9],[1,4,3],[1,4,9],[1,2,3],[1,2,9],[1,4,3],[1,4,9]] 8 effects because 2^3
Robert Mennell
@skatcat31
Apr 13 2017 19:19
https://goo.gl/35lcqD made it a little easier to understadn for me
shows that it kind of goes [[L,L,L],[L,L,R],[L,R,L]...[R,R,R]] and is kind of like building the truth table
https://goo.gl/mBx3k1 ooh truth table generator XD
Denis Stoyanov
@xgrommx
Apr 13 2017 20:04
@skatcat31 reduceRight((x, a) => ap(flip(concat), map(prepend(x)))(a), [[]], [1,2,3])