Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 22:17
    CrossEye commented #2779
  • Jan 31 2019 21:04
    ArturAralin commented #2779
  • Jan 31 2019 20:08
    CrossEye commented #2779
  • Jan 31 2019 18:56
    buzzdecafe commented #2631
  • Jan 31 2019 18:09
    ArturAralin commented #2779
  • Jan 31 2019 16:18
    CrossEye commented #2779
  • Jan 31 2019 16:10
    CrossEye commented #2631
  • Jan 31 2019 16:06
    CrossEye commented #2777
  • Jan 31 2019 14:44
    ArturAralin opened #2779
  • Jan 31 2019 07:39
    inferusvv commented #2631
  • Jan 31 2019 03:07
    sespinozj commented #2771
  • Jan 31 2019 02:33
    machad0 commented #2771
  • Jan 31 2019 02:26
    JeffreyChan commented #2777
  • Jan 30 2019 14:30
    CrossEye closed #2777
  • Jan 30 2019 12:13
    vanyadymousky updated the wiki
  • Jan 30 2019 01:42
    JeffreyChan commented #2777
  • Jan 29 2019 21:06
    vanyadymousky updated the wiki
  • Jan 29 2019 16:28
    CrossEye commented #2777
  • Jan 29 2019 15:50
    mbostock commented #2772
  • Jan 29 2019 15:48
    CrossEye commented #2772
Christer Nilsson
@ChristerNilsson
Ramda got a little bit easier to use in Observable today. See this notebook
Christer Nilsson
@ChristerNilsson
@rajukc530 Please give an example of what you would like to do.
Arian R
@arianra
I forgot how magnificent this channel is

isOdd taken from Ramda Adjunct:

const isOdd = both(isInteger, pipe(flip(modulo)(2), complement(equals)(0)));

Seven keywords. Seems a lot.

This is absolutely glorious

thanks for making me feel all warm and tingly inside
Christer Nilsson
@ChristerNilsson

@arianra I guess

isOdd = x % 2 == 1

does not tingle that much!

Arian R
@arianra
ramda shall be the last remnants of humanity when github's skynet takes over
Christer Nilsson
@ChristerNilsson
I'm hoping for an ai that produces ramda code given input and output.
Arian R
@arianra
don't kill my dream of being part of the rebellion
Christer Nilsson
@ChristerNilsson
One day ramda will be considered the new assembler.
Joshua Travis
@jktravis

Is there a Prettier plugin to better handle composes? For example:

const uniqAndSortByLabel = R.compose(
    R.sortBy(R.prop('label')),
    R.uniqBy(R.compose(
        R.toLower,
        R.trim,
        R.prop('label'),
    )),
)

will be transformed to this:

const uniqAndSortByLabel = R.compose(
    R.sortBy(R.prop('label')),
    R.uniqBy(R.compose(R.toLower, R.trim, R.prop('label')))
);

I know there's the comment // prettier-ignore, but I also don't want to put that everywhere I'm using compose.

laputan_machine
@laputan_machine:matrix.org
[m]
Hello, is there a callN function in ramda? e.g. if I wanted to repeat something n times, what would be the idiomatic way of doing this in Ramda?
Nik
@niksosf
@laputan_machine:matrix.org there is a ‘times’ function. Does that help ?
So ‘’’ times( (n)=> fn(), 42)’’’
Lewis
@6ewis
any suggestions to refactor this?
Christer Nilsson
@ChristerNilsson
@6ewis Might be a good idea to give one or more I/O-pairs instead of code.
Dustin Stiles
@dustinws
Hello, is there a clean way to rename a property on an object? I have a function that does it but I wasn't sure if ramda has a nice one liner.
// What I have for turning a mongo document into a domain record
const renameIdProp = ({ _id, ...params }) => ({
  ...params,
  id: _id,
});
5 replies
Abhishek Dubey
@ad99526
Hi guys
I need a ramda function which maps and filters over one iteration
[1,2,3,4].mapAndFilter(el => el !== 1 && 0) //should return [0,0,0]
Christer Nilsson
@ChristerNilsson
@ad99526
map(el => 0, filter(el => el != 1, [1,2,3,4]))
I think you need a transducer. Check out this video: https://youtu.be/SJjOp0X_MVA
Abhishek Dubey
@ad99526
@ChristerNilsson this loops the array twice
@ChristerNilsson i need something like flatMap
3 replies
Christer Nilsson
@ChristerNilsson
@ad99526 It's ok to augment Ramda. If you need a flatMap, just define it in vanilla javascript and add some curry. Remember, Ramda is not cut in stone. A plain for loop is 250% faster than using map and filter.
Charles Hughes
@chughes87
Ramda's flatmap is chain
Andy Mac
@zxol
Can someone please help me understand the purpose of ramda's internal function _curry1? Specifically, the path of when args is zero, return f1?
export default function _curry1(fn) {
  return function f1(a) {
    if (arguments.length === 0 || _isPlaceholder(a)) {
      return f1;
    } else {
      return fn.apply(this, arguments);
    }
  };
}
2 replies
is it part of the placeholder logic, as well?
I'm trying to write my own curry function and i was wondering if I can ignore this part of ramda if I don't implement placeholders
klequis
@klequis

I have been going through Ramda's source code as a learning exercise and don't understand the following:

Here is a simplified curry3 function

import _curry2 from './fns/_curry2' // copy of Ramda function
import _curry3 from './fns/_curry3' // copy of Ramda function

export function curry3(fn) {
  return function f3(a, b, c) {
    const argsLen = arguments.length
    log('curry3 argLen', argsLen)
    switch (argsLen) {
      case 0:
        return f3
      case 1:
        return _curry2(function (_b, _c) {
          return fn(a, _b, _c)
        })
      case 2:
        return _curry1(function (_c) {
          return fn(a, b, _c)
        })
      case 3:
        return fn(a, b, c)
    }
  }
}

Wrap a function in it

const c3 = curry3(function curryMe3(a, b, c) {
  return `curryMe3: ${a}, ${b}, ${c}`
})

const c3 = curry3(function curryMe3(a, b, c) {
  return `curryMe3: ${a}, ${b}, ${c}`
})

And call it

log('c3-0', c3())
// -> argLen 0
// -> c3 [Function: f3]

log('c3-1', c3(1))
// -> argLen 1
// -> c3 [Function: f2]

log('c3-2', c3(1, 2))
// -> argLen 2
// -> c3 [Function: f1]

log('c3-3', c3(1, 2, 3))
// -> argLen 3
// -> c3 curryMe3: 1, 2, 3

So c3 receives 1 argument as fn. What I dont understand is how the arguments passed to curryMe3 get into f3 as 0, 1, 2 or 3 separate arguments.

klequis
@klequis
@zxol I wrote my own version of _curry3 minus the placeholder logic. It appears to be working well
salmondorf
@salmondorf:matrix.org
[m]
Is there a good way to refactor this function?
const sumEq = curry((n, list) => pipe(sum, equals(n))(list));
oomusou
@oomusou
@salmondorf:matrix.org How about let sumEq = useWith (equals, [identity, sum]) ?
salmondorf
@salmondorf:matrix.org
[m]
Hmmm. Looks like that will probably work. Thanks!
Nicholai Nissen
@Nicholaiii
Is there a ramda function that is the equivalent of (e: T | T[]): T[] => Array.isArray(e) ? e : [e]
1 reply
klequis
@klequis
I figured it out - yeah
Marcelo Olivas
@mfolivas

How can I validate that a request is a JSON object? I did something like this:

const getTags = (request) => {
  if (isEmpty(request) || !is(Object, request)) {
    throw new TypeError(
      'The #request is required and needs to be an JSON object'
    )
  }

But then I realized that is(Object, []) returns true

Marcelo Olivas
@mfolivas
I endup doing this:
export const isNullOrEmpty = (request) => isNil(request) || isEmpty(request)

/**
 * Check if the incoming request is either empty, null, or undefined and if it
 * is not a JSON object
 *
 * @param {*} request - incoming request
 * @returns {boolean} true when the request is either null, undefined, or empty,
 * and it is not a JSON object
 */
export const isEmptyOrNotJSONObject = (request) =>
  isNullOrEmpty(request) || request.constructor !== Object
3 replies
deepcode
@deepcode:matrix.org
[m]
Is there anyone find sometimes lines of code write in ramda is more than plain js?
2 replies
😀
James Ramm
@JamesRamm

Hi there!
Got a function combination problem and was wondering if Ramda could help me write it in a point-free style.

Basically, I have 2 functions both which take the same input. One function returns a Promise which resolves to a string and the second function returns a string. I want to join the results of the two functions using path.join.

I.e, non point-free:

const fn = obj => getString1(obj).then(s1 => path.join(s1, getString2(obj))

Using ramda's join with a forward-slash instead of path.join is acceptable. Is there a point-free way of combining these functions?
I thought perhaps lift could help but I figure it out with the promise-returning function.

7 replies
QP
@theqp
isthere a pipeWith function which starts with the last parameter?
what I mean by that instead of pipeWith(f, g, x) i can write pipeWith(x, f, g)
1 reply
woss ( Daniel Maricic )
@woss:matrix.org
[m]

i don't think so. maybe you can use R.reverse for the arguments

const pipeWhileNotNil = R.pipeWith((f, res) => R.isNil(res) ? res : f(res));
const f = pipeWhileNotNil(R.reverse[Math.pow, R.negate, R.inc])

Note this code is only for demo, prob it will not work @theqp

woss ( Daniel Maricic )
@woss:matrix.org
[m]

:point_up: Edit: i don't think so. maybe you can use R.reverse for the arguments

const pipeWhileNotNil = R.pipeWith((f, res) => R.isNil(res) ? res : f(res));
const f = pipeWhileNotNil(R.reverse[Math.pow, R.negate, R.inc])

Note this code is only for demo, prob it will not work but you got the idea 🙂 @theqp

Narley Brittes
@narley
Hey folks, I friend of mine released a new javascript repl (https://github.com/tim-crisp/javascript.lol). I know this is not a ramda topic, but the guy is a ramda addicted and this project came out as a away for him to quickly prototype with ramda.
Tim
@tim-crisp
Hi all, I wasn't aware of this community until @narley told me about it, seems like a really awesome place to talk ramda.
I've put the solution @nfantone provided to the question @JamesRamm asked into a javascript.lol REPL to demonstrate it. Feel free to have a look and if you have any feedback raise an issue on the github repo!
woss ( Daniel Maricic )
@woss:matrix.org
[m]
hi @tim-crisp i can't find the source code 🙂 i'd love to see how you built this
Tim
@tim-crisp
Hi @woss:matrix.org I'm not releasing the source code just yet. I'd like to see how the community responds to the app first and in all honesty it needs a bit of a tidy up before it deserves to go public! When the day comes and I decide to release it, the source will be hosted on the github repo that @narley mentioned. Thanks for showing interest, watch this space 😉