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
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 😉
woss ( Daniel Maricic )
@woss:matrix.org
[m]
cool. what cought my eye is the dynamic loading of the packages. do you mind a DM?
Tim
@tim-crisp
https://skypack.dev is the magic behind that
woss ( Daniel Maricic )
@woss:matrix.org
[m]
yeah, saw that. it's brilliant
that might actually solve my problem. 😀
Tim
@tim-crisp
In all honesty mate it does all the hard work, I'd highly recommend it
woss ( Daniel Maricic )
@woss:matrix.org
[m]
on this link there is plenty of ramda code for recursive execution and loading. although this works only on node but YES now i can do it in browser https://github.com/anagolay/js-sdk/blob/main/sdk/core/src/executeOperation.ts#L42
Tim
@tim-crisp
Nice. I'm loving some of the comments in that repo :joy:
Charles Hughes
@chughes87
kind of proud of this little tool I made last night:
const tagger = curry((tag, text, template) => pipe(
  when(
    includes(tag),
    pipe(
      replace(tag, text),
      tagger(tag, text)
    )
  )
)(template))

const applyTags = (tags, template) =>
  pipe(
    toPairs,
    map(over(lensIndex(0), s => `{${s}}`)),
    reduce(pipe(append, apply(tagger)), template)
  )(tags)

const tags = {
  test: 'tasty test',
  cheese: 'amazing smoked gouda'
}
const template = 'this is a {test}. I love {cheese}.'

applyTags(tags, template) // "this is a tasty test. I love amazing smoked gouda."
4 replies
sd
@sdebaun
stupid question. includes is T => T[] => boolean. Is there an equivalent function in ramda that is T[] => T => boolean?
i just add my own:
const includedIn: <T>(list: T[]) => (item: T) => boolean =
    list => item => includes(item)(list)
i just want to make sure that i'm not doing something that ramda already supports that i just cant find in the docs XD
1 reply
Mike Vosseller
@mpv_twitter

Hi, I'm new to functional programming and Ramda. How might you improve these functions? Can any be made pointfree? Thank you!

//
// elementAfter(el, list) returns the element after el in the list
// (wapping to the beginning if needed)
// how would you improve these functions? can any be made pointfree?
//
const indexAfter = (index, list) => mathMod(inc(index), length(list))
const indexAfterElement = (el, list) => indexAfter(indexOf(el, list), list)
const elementAfter = (el, list) => nth(indexAfterElement(el, list), list)
elementAfter('c', ['a', 'b', 'c']) // 'a'

Ramda REPL: https://tinyurl.com/yhwpgykj

11 replies
Joshua Travis
@jktravis
Hi! I'm wanting to use a transducer to do a filter, map on a data set and then join then via effectively a groupBy. While I can write my own joiner, I'd like to know if there's a way that I can use the Ramda groupBy instead.
// This fails cause "reduce: list must be array or iterable"
R.transduce(mapfilterComp, R.groupBy(R.prop('programId')), {}, settings)
4 replies
QP
@theqp
@mpv_twitter I could improve indexAfter
https://tinyurl.com/yhkxl5u5
QP
@theqp
@mpv_twitter I could do it even more with reader monad
QP
@theqp
I made it point free with the help of pointfree.io
image.png
QP
@theqp
I made it 100% point free but I couldn't read it lol
https://tinyurl.com/yfpvf2cu
QP
@theqp
i just noticed someone solved it, also there is reader monad in ramda
https://tinyurl.com/ydst7myu
Mike Vosseller
@mpv_twitter
@theqp Thank you!