These are chat archives for ramda/ramda

4th
Aug 2017
Michael Hurley
@buzzdecafe
Aug 04 2017 00:29
@gabejohnson @Bradcomp i would want something to fill that role though; transducers are all we have that is "lazy-ish"
i wouldn't object to removing them from core if there was a way to plug them in when desired
Gabe Johnson
@gabejohnson
Aug 04 2017 01:42
@buzzdecafe pulling the _x* functions out into a separate lib makes sense.
Stephan Meijer
@smeijer
Aug 04 2017 08:01
Is it possible to have the type sorting, based on the lookupTable below? I think I need to use R.useWith?
const lookupTable = {
  Type1: 1,
  Type2: 3,
  Type3: 2,
};

R.sortWith([
  R.descend(R.prop('type')),
  R.ascend(R.prop('title')),
])(items)
qiufeihai
@qiufeihai
Aug 04 2017 10:03
how to use ramda do this
 [{ctime:1}].map(item => {
    item.useTime = 1000 - item.ctime
    return item
  })
Kurt Milam
@kurtmilam
Aug 04 2017 12:24
@qiufeihai This should do the trick (REPL):
 R.map(item => {
    item.useTime = 1000 - item.ctime
    return item
  }, [{ctime:1}] )
Or did you want to refactor the internal function, as well?
Kurt Milam
@kurtmilam
Aug 04 2017 12:29
If so, this should do the trick (REPL):
R.map( R.converge( R.assoc( 'useTime' )
                 , [ R.o( R.subtract( 1000 ) )
                        ( R.prop( 'ctime' ) )
                   , R.identity 
                   ] 
                 )
     )
     ( [ { ctime:1 } ] )
Vadim Nekrasov
@barbiturat
Aug 04 2017 13:19
Is there a short way to flip non-first two arguments of function in ramada?
In other words, to make this:
(a -> c -> b -> d) -> a -> b -> c -> d
Kurt Milam
@kurtmilam
Aug 04 2017 13:58
@barbiturat How about this? I think it will work as long as you know you'll always pass a in on its own, first:
fn = a => b => c => d => doStuff
fn2 = R.o( R.flip, fn )
Vadim Nekrasov
@barbiturat
Aug 04 2017 14:02
But what if i want to flip third and fourth arguments?
I’m looking for an universal solution
Matthew Willhite
@miwillhite
Aug 04 2017 14:11
Just curious @barbiturat, what is the use case?
Vadim Nekrasov
@barbiturat
Aug 04 2017 14:15
I’m just learning ramda. Trying to create simple solution for a method like “flip args”
For example:
// flipArgs(firstIdx, secondIdx, fn)
const fn = curry((a, b, c, d) => a + b + c + d);
flipArgs(2, 3, fn)('a', 'b', 'c', 'd') //-> ‘abdc’
Matthew Willhite
@miwillhite
Aug 04 2017 14:22
I come from an OO, imperitive background…sometimes when I’m trying to figure something like this out, I’ll write something imperative first. Then I can better visualize the pieces and start to break it down into declarative bits. The more experience I get the less I need to go down that route… I think it is just a matter of brain training ;)
Or you can just list out the steps to start, I’d think something like this:
  1. Take all of the arguments
  2. Pull out the indexed arguments
  3. Reconstruct the list, inserting the indexed arguments in their new position
  4. Apply that new list to the provided function
Myron Mavko
@mmavko
Aug 04 2017 16:42
This message was deleted
Here's what I'm missing in Ramda:
// Allusion to Clojure Threading Macros
// (https://clojure.org/guides/threading_macros)
function thread(o) {
    return (...fns) => R.pipe(...fns)(o);
}
Jonathan Chang
@jdkschang
Aug 04 2017 17:12
Is there a way to convert dot chaining functions into a compose style syntax?
Also are there wiki/faq’s for learning how to read type signatures, etc ?
I’ve come across invoker, but unsure if that’s the best way to move forward
Kevin Wallace
@kedashoe
Aug 04 2017 17:14
hi @jdkschang . here is an intro to type signatures: https://github.com/ramda/ramda/wiki/Type-Signatures
Jonathan Chang
@jdkschang
Aug 04 2017 17:15
awesome!
also found out how to convert object methods into composable functions here: https://egghead.io/lessons/javascript-convert-object-methods-into-composable-functions-with-ramda
Kevin Wallace
@kedashoe
Aug 04 2017 17:15
cool
Jonathan Chang
@jdkschang
Aug 04 2017 17:15
thanks @Andrew Van Slaars if he’s in here
Kevin Wallace
@kedashoe
Aug 04 2017 17:16
ya, invoker is good for that
Jonathan Chang
@jdkschang
Aug 04 2017 17:23
thanks @kedashoe for the type signatures link, it’s exactly what I was looking for!
Kevin Wallace
@kedashoe
Aug 04 2017 17:25
np :)
Vadim Nekrasov
@barbiturat
Aug 04 2017 20:50
@miwillhite Eventually I made this:
const argsToArray = unapply(identity);

const takeArgs = curryN(2, compose(
  apply(take),
  splitAt(1),
  argsToArray
));

const sliceByCount = converge(slice, [identity, add, nthArg(2)])

const reverseElems = converge(insertAll, [
  identity,
  compose(reverse, sliceByCount),
  remove
]);

const reverseArgs = converge(compose, [
  compose(apply, nthArg(2)),
  compose(apply(reverseElems), takeArgs(2)),
  always(argsToArray)
])

const fn = (a, b, c, d, e) => a + b + c + d + e;
const reversed = reverseArgs(1, 3, fn);

reversed('a', 'b', 'c', 'd', 'e') //-> “adcbe"
Robert Oh
@Rob0h
Aug 04 2017 23:47
hi, encountered some strange behavior with ifElse and compose and wondering if anyone knew why. the code below will return a function; however when replaced with a R.cond, will return the correct answer (REPL)
const sortedData = [
  { field: 1},
  { field: 2},
  { field: 3},
]
const matcher = R.compose(R.filter(R.__, sortedData), R.whereEq);

R.ifElse(
  R.isNil,
  R.always(null),
  matcher
)({field: 2});