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
Pedro Ávila
@aviladev
Thank you guys!
Ben Carp
@carpben
Hi,
What is the deal with Ramda's tree shaking? Is it similar to Lodash? U need to manually import 'ramda/pick'?
vinodsudini
@vinodsudini
Hi, when can I expect the new version with security fix for Redos ?
ed@sharpertool.com
@kutenai
I am using this const hasRequiredKeys = R.allPass(R.map(R.has, disallowed_keys)) to insure required keys are in an object. I now want to reverse that, and check to insure a set of 'disallowed' keys are NOT in there.
2 replies
Pedro Ávila
@aviladev

I think I found a bug in includes:

const fn = includes(__) (['foo', 'bar'])
const fn2 = includes(__, ['foo', 'bar'])

console.log(
  fn('foo'), // false
  fn('bar'), // false
  fn2('foo'), // true
  fn2('bar'), // true
  fn2('not present'), // false
)

REPL: https://tinyurl.com/yzlg72gq

6 replies
Joshua Travis
@jktravis
Hi. We have several projects that were using lodash. We’ve started introducing Ramda. But now we want to see what it would take to replace lodash completely. My question is, does anyone have a codemod or similar to help facilitate this process?
James Ramm
@JamesRamm

Does ramda have a point-free way to do this:

const callMethod = obj => obj.someMethod;

I could do:

const callMethod = R.compose(R.call, R.prop('someMethod'))

But that does not seem any clearer and certainly less concise. I was thinking perhaps ramda has a builtin fn for it, but I couldn't find it...

Ideally, generically, e.g.:

const callMethod = curry((name, obj)  => obj[name]())
4 replies
nik so
@nik_so_twitter
Hello James that method is call invoker
Aron Griffis
@agriffis
The Ramda docs reference the Maybe type, for example for traverse, but it's not part of Ramda that I can tell. Is there an implementation people commonly use?
1 reply
KAMi KZ
@kamikz85_twitter
@agriffis so I'd say any ADT libraries that implements the fantasy-land specifications would do the trick. So personally I use folktales, but i think crocks will do the trick, too.
Aron Griffis
@agriffis
@kamikz85_twitter Ok, thanks!
Soya
@Soya-xy
Is there a _.get (Object, 'a.b.c', 'default ") like Lodash; method is taken from the string
8 replies
Joshua Travis
@jktravis
No. But you can create your own wrapper for it pretty easily.
Dennie de Lange
@tkvw
is there a better way to do this in typescript? I need to do all kind of type assertions because of nth:
R.pipe(
  R.toPairs,
  R.filter(R.pipe(
    R.nth(1) as (value: [string,string]) => string,
    R.both(R.pipe(R.isNil, R.not), R.pipe(R.startsWith('workspace:'), R.not))
  ) as (v: [string,string]) => boolean),
  R.fromPairs
) as (data: Record<string,string>) =>Record<string,string>
Peter Blockman
@peterblockman
This message was deleted

Hi, I am having this problem with TS type. Do you have any idea?

error

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'concat_list_10<File>' is not assignable to parameter of type 'Morphism<unknown, unknown>'.
      Types of parameters 'b' and 'value' are incompatible.
        Type 'unknown' is not assignable to type 'unknown[]'.ts(2769)
over.d.ts(106, 5): The last overload is declared here.

The code

const updateFiles =  R.concat(files)
    set(state => {
        return R.over(lensFiles, updateFiles, state)
    })
export interface File {
    id: string;
    link: string
}

interface
```export interface UserData {
    _id: string | undefined;

    files: File[];
}

state example

const state = {
 user: { data: {
    id: 1,
    files : [{id:"1", link: "somelink"}]
  }}
}

Version

    "ramda": "^0.27.1",
    "@types/ramda": "types/npm-ramda#dist",
#!/bin/BasH
@bas080
over(compose(somePathLens, indexIsOdd), add(1))({a: {b: [1,1,1,1]}}) // => {a: {b: {[1,2,1,2]}}
How would I implement a lens that works on a subset of an array. In this case only the items where the index is odd.
klequis
@klequis
For those who are developing JavaScript apps but not using Typescript I'm wondering if you are just writing traditional JS or if you have adopted other techniques or tools that add types or help you manage the absence of types. I'm asking because I really like the benefits of using types but find TypeScript quite verbose. I'm pretty well versed in the issues & possibilities with using Functional Programming and/or Ramda with TypeScript, so not asking bout anything in that direction.
Joshua Travis
@jktravis
[I] don't use any tool for types 'cept JSDoc. Most modern IDEs will give a decent auto-complete based on imports and such by using the TS engine as more of a linter when doing so, but without the extra build step or complexity in the build.
klequis
@klequis
@jktravis Thanks for the tip. I see there is a section in the TS handbook for doing that.
Alexei Kozhushkov
@joystick
Good day to all, could you please help me to point-free this one:
// pageBelongsToDocumentWith :: Int -> Page -> Boolean
const pageBelongsToDocumentWith = documentIndex => compose(
  equals(documentIndex),
  prop('documentIndex')
)
wangzengdi
@adispring
@joystick
const pageBelongsToDocumentWith = R.useWith(R.identity, R.prop('documentIndex'))
Alexei Kozhushkov
@joystick

@joystick

const pageBelongsToDocumentWith = R.useWith(R.identity, R.prop('documentIndex'))

Magic 😀

3 replies
Daniel
@dbstraight

So how long does it take before ramda and point-free programming stop making you feel dumb because of what you can't figure out? :laughing:

Trying to figure out how to point-free this and just..... can't get my brain around it. It has to be so easy.

f => x => f(x)(x)
2 replies
Djordjenp
@Djordjenp
Can someone tell me what I am doing wrong here?
import {__, curry, add} from "ramda";

const subtractNums = (a,b,c) => a - (b + c);

const subtractCurried = curry(subtractNums);
const func = subtractCurried(__)(5)(6);

console.log(func(15)) // -16
4 replies
Nicolas Ramirez
@kamatheuska
Hi everyone! I am reviewing a PR where the dev is using nested pipes. Just from the looks of it, I think there must be a better solution. Could you give me some feedback on the snippet?:
 const filterFns = pipe(
    reject(pipe(values, head, isNilOrEmpty)),
    ... // some other code, not important for now
    ])),
  )([...$or, ...$and]);
pathTo and isNilOrEmpty are helpers in our code based on Ramda...
In principle, it seems to be very ugly code, but I am not a functional wizard programmer, so I am no sure how to build an argument or working alternative to it
any ideas?
5 replies
Akira Cai
@blackwindforce
The document just released 0.28.0, some issues found so far
#!/bin/BasH
@bas080
includes(_, [1,2,3]) // => false
_ is indeed not an item in the array. But i expected different behavior similar to flip(includes). Mentioning it here because I think this issue has already been raised.
2 replies
Djordjenp
@Djordjenp

I am having an issue understanding next lens code:

import {compose, lensProp, view} from "ramda";

const truth = compose(
    lensProp('foo'),
    lensProp('bar'),
    lensProp(1),
)

const obj = {
    foo: {
        bar: [false, true]
    }
};

console.log(view(truth, obj)) // true

I could understand if we used pipe instead of compose, but compose performs right-to-left function execution and that confuses me.

3 replies
Djordjenp
@Djordjenp
Hello,
I am failing to see how I can use pipeWith/composeWith functions with promises to make async pipeline, and how to catch errors. Can i get some help?
const fetchPlanets = async (url) => await fetch(url);
const checkResponse =  (response) => response.ok ? response : 'error';
const getJson = async (response) => await response.json();
const logger = data => console.log(data);

const gettingData =  pipe(
    fetchPlanets,
    checkResponse,
    getJson,
    logger
)


gettingData('https://swapi.dev/api/planets');
aksoo5
@aksoo5
Hello, I got this working: https://pastebin.com/y2559aR1 -- what did I do wrong/miss and how can I simplify it?
D
@keeoth_gitlab

Hi! I'm using Ramda in a project and editing with VSCode. I'm trying to document my code with JSDoc but VSCode's Intellisense automatically infers my function types (so doesn't show my JSDoc comments). Does anyone know how to force VSCode to stop inferring if there is JSDoc documentation?

/**
 * @param { Array<Number> } arrayOfNumbers
 * @return { Number } sum - the sum of the arrayOfNumbers
 */
const getSumOfArrayElements = reduce (add, 0)

Intellisense just shows what R.reduce returns:

const getSumOfArrayElements: (list: readonly any[]) => number

Asking here because I figure other Ramda users may have run into this. Thanks!

Joshua Travis
@jktravis
You might have to create a function wrapper and document that. /shrug
Otherwise it’s just a variable holding a reduce function.
D
@keeoth_gitlab
@jktravis Thank you for the reply! And yeah, either that or switch to a different editor :cry: Ha. Webstorm handles this use case just fine so it'd be unfortunate to change the way we write code just because of VSCode :grimacing:
The Very Angry Caterpillar
@ti_estin_twitter

I don’t know what I have to do facing the following error concerning type.
Could someone help me with this?

Code

import { concat, flip, pipe } from 'ramda'
const concatAfter = flip(concat)
const foo = [1, 2, 3]
const bar = [4, 5, 6]

type Exec = (x:number[]) => number []
const exec:Exec = pipe(
  concatAfter(foo),
  concatAfter(bar)
)

Error

[tsserver 2322] [E] Type '(s2: string) => string' is not assignable to type 'Exec'.
  Types of parameters 's2' and 'x' are incompatible.
    Type 'number[]' is not assignable to type 'string'.

Packages

ramda@0.28.0
@types/ramda@0.27.64
wangzengdi
@adispring
@ti_estin_twitter @types/ramda not support curry well, if you use ramda with ts, do not use flip, and write type explictly:
const concatAfter = (list1: number[]) => (list2: number[]) =>
  concat(list2, list1);
const foo = [1, 2, 3];
const bar = [4, 5, 6];

type Exec = (x: number[]) => number[];
const exec: Exec = pipe(concatAfter(foo), concatAfter(bar));
2 replies
Matt Diamond
@mattdiamond
suggestion: might want to remove the broken codeclimate test coverage link on the homepage
not a huge deal... it just looks a bit sloppy to have a broken image link prominently displayed at the top, esp. since the homepage may be someone's first impression of Ramda
(great work on the new release, btw!)
#!/bin/BasH
@bas080
splitWhen does not drop the "split on item" but splitWhenever does. I find that inconsistent.
1 reply
I find keeping the value that was split on more useful
Mike Lambert
@lax4mike
Hey folks! I'm having a really hard time trying to use ramda with typescript. I installed @types/ramda and I made a code sandbox with some code here https://codesandbox.io/s/youthful-borg-rh1d4b?file=/src/index.ts
I'm seeing No overload matches this call.. I'm not really sure what it's trying to tell me... has anyone encountered something similar before?
3 replies
Valerii Petryniak
@valerii15298
hello, i am new to Ramda:)

Can you explain me why ramda does not work with plain objects in typescript? ```const name1 = R.prop("name", { test1: 1, name: "Ivan" }); //works

const extractName = R.prop("name");
const name2 = extractName({ test1: 1, name: "Ivan" }); //typescript complains

const obj = { test1: 1, name: "Ivan" };
const name3 = extractName(obj); //works
```

pihentagy
@pihentagy
Does ramda have such a reduce, which does not need an accumulator value (and in exchange requires a non-empty array)?
4 replies