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
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
Julian Domke
@judocodes

Hey guys, given an array of numbers, I need to partition elements by difference to their preceding element. Example:

const difference = 10;
const elements = [0,5,10,15,20,30,35];
// desired result:
[[0,5,10,15,20], [30, 35]]

Is there something in the library that allows looking at the previous element's value when iterating?

4 replies
Yosevu Kilonzo
@yosevu

What is a functional way to find a specific size object from this kind of nested data structure. For example, I want to iterate until I find a size { id: 6 } and return it. Do I have to use 3 nested loops?

Input:

[
    {
      id: 'a',
      colors: [
        {
          name: 'blue',
          sizes: [
            { id: 1 },
            { id: 2 },
            //...
          ]
        },
        {
          name: 'green',
          sizes: [
            { id: 3 },
            { id: 4 },
            //...
          ]
        },
        //...
      ]
    },
    {
      id: 'b',
      colors: [
        {
          name: 'black',
          sizes: [
            { id: 4 },
            { id: 6 },
            //...
          ]
        },
        {
          name: 'white',
          sizes: [
            { id: 7 },
            { id: 8 },
            //...
          ]
        }
      ]
    },
    //...
  ]
8 replies
D
@keeoth_gitlab

I'm sure a number of you may have already heard but there is a new ECMAScript proposal for "Types as Comments". It's basically a way to allow TypeScript and Flow code to run in the browser as is. It's just Stage 0 and might get shelved before ever making it somewhere but the interesting thing is that it's being pushed by representatives from Microsoft and it already has some heavy hitters from the ECMAScript proposal community engaging with it. As we all know, using TS for functional programming has some frustrating limitations and hoops to jump through. So I just want to make sure the functional JS is community aware of the proposal and encourage people to go explore the proposal and speak up so we're represented in the discussion.

Thanks!

https://github.com/giltayar/proposal-types-as-comments

talhaguy
@talhaguy
Does Ramda have a function that maps array values as arguments to an array of functions? Eg I'm looking for: [1, 2], [fn1, fn2] to be fn1(1) and fn(2). I made it myself but curious if there's a built in function for this.
5 replies
zrn
@zrn:matrix.org
[m]

is there something like until but returning array of all values instead of last one?
like in example

R.until(R.gt(R.__, 100), R.multiply(2))(1) // => 128

it would return [1,2,4,8,16,32,64,128]

zrn
@zrn:matrix.org
[m]

ok I found unfold

const f = n => n > 100 ? false : [n, n * 2];
R.unfold(f, 1); // =>[1,2,4,8,16,32,64]

```

talhaguy
@talhaguy
What is the idiomatic way in Ramda to bring along temporary variables that need to be used later in piped functions? E.g. let's say I have 2 functions in a pipe. A param is given to the first function and produces a result. This result is piped to the 2nd function. However I need the original param as well in this function. Right now I've been accumulating either an object or an array with the temporary calculations or variables I might need and it works, however I was looking for a potentially better way. Thanks!
wangzengdi
@adispring
@talhaguy You can use R.converge with R.identity, or R.chain, or R.ap
wangzengdi
@adispring
Function can be regard as Reader Monad, which can be used to pass the same param to multiple procedure.
talhaguy
@talhaguy
@adispring - Thank you! Side note, I came across a nice clean way to do it in fp-ts (https://gcanti.github.io/fp-ts/guides/do-notation.html) which seems to follow the do notation from Haskell. Will try what you suggested in Ramda.
gpindia
@gpindia:matrix.org
[m]
:point_up: Edit: Also, I have doubt if ramda functions can cause environment related issues because I am facing this issue on a particular environment, otherwise it works fine. Can anyone help what can cause this?
Marcus Blättermann
@essenmitsosse

I had a look at https://github.com/ramda/ramda.github.io and was actually wondering, if there is some kind of build process involved, that just pushes to the repo, or if for new versions, someone just copies the folder and edits everything by hand. Would love to contribute to the docs, but wanted some understanding beforehand.

(hope this is the right channel for this)

wangzengdi
@adispring
@essenmitsosse ramda generate its document website automatically based on ramda/ramda repo.
JoeIsCool
@JoeIsCool
Hi, can you use transducers with functions like groupBy and CollectBy?
Charles Hughes
@chughes87
Anyone know good companies/teams in SF bay area that use Ramda? I am looking for a job. 8 years JS exp split pretty even btw frontend and backend.
Valerii Petryniak
@valerii15298
Hello, guys. @essenmitsosse @adispring . I was trying to use autocompletion for R.omit but appears there is no one) what do you think about this typing of omit instead of current one: export function omit<T extends object, K extends keyof T>(names: readonly K[], obj: T): Omit<T, K>;
1 reply
T extends object prevents to pass something else, bcs now it allows to pass anything. And K extends keyof T allows to narrow types and gives us nice autocompletion.