## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
• Create your own community
##### 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
• 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
Tushar Mathur
@tusharmath
Is there a way to convert a function like A, A => B to A => B?
Essentially passing the same input twice?
I need a higher order function that can do this.
something like — converge(identity, identity)?
is there a better way?
Matthias Seemann
@semmel
@tusharmath What is wrong with unnest :: (a→a→b)→a→b ?
[pihentagy]
@pihentagy:matrix.org
[m]

What is the simplest way to remove properties, which have null values?

So

const a = { hello: 'world', nobody: null };
const b = ??? ; //
b == { hello: 'world'};
2 replies
[pihentagy]
@pihentagy:matrix.org
[m]
Nice there is https://ramdajs.com/repl/ but what if I would like to show typescript snippet? Is there a platform, where I can load ramda and has ts support?
Daniel Power
@DanielPower_gitlab

Hi. I'm new to FP and Ramda. I'm using Typescript and running into a bit of a developer experience problem with pipe, and I'm wondering if there's a more elegant way to express what I'm writing.

  return pipe<
[QuestLog],
QuestLog,
QuestLog,
QuestLog,
QuestLog,
QuestLog,
QuestLog,
QuestLog,
QuestLog
>(
createUser("dan"),
createUser("rob"),
createUser("estaban"),
createUser("colin"),
createUser("matt"),
createCampaign(campaignUuid, "The Rainbow Sands", "matt"),
)({
campaigns: [],
users: [],
});

It seems that pipe cannot infer the types of my mutation functions, each of which are QuestLog -> QuestLog. To handle this, I have to write out a huge cluster of types in the template.

Is there either a way to have pipe infer the type appropriately, or a way to tell it that all arguments will be of the same type, so I only have to specify it once?

zrn
@zrn:matrix.org
[m]
I m not good at ramda but it seems you do many times same function just with new arguments, maybe just create a new function that would take an array of arguments and reduce it using your function?
zrn
@zrn:matrix.org
[m]
also you shouldn't mutate inputs if you do fp
Alexei Kozhushkov
@joystick

Hi there, i'm looking for a way to Ramda-mize the following:

const foo = ('someMethod', 'someParam') => x = > x.someMethod(someParam)

Much appreciated 🙃

3 replies
Tristan Forward
@tforward

This question is related to the Ramda Docs and Html sematics.

The Ramda Docs page has headers like "add", that when clicked navigate within the current window to the add function.

Looking at the html:

<h2>
<span class="pull-right">
<span class="label label-category">Math</span>
<a target="_blank" title="View source on GitHub" href="https://github.com/ramda/ramda/tree/v0.28.0/source/add.js"><small class="glyphicon glyphicon-new-window"></small></a>
</span>
</h2>

Mdn docs for the a tag say using the ID creates the link,

<p><a href="#Section_further_down">
</a></p>

<h2 id="Section_further_down">Section further down</h2>

Yet in Ramda docs there is no ID, so how does it still work?

zrn
@zrn:matrix.org
[m]
it is in fact there
but it's strange that h2 is not inside that div
Tristan Forward
@tforward
Thank you! Yeah that div is fairly odd. Not sure why the id and class are not just on the section tag itself vs. this ghost div element.
Justin Carrus
@jcarrus

Hi everyone, I'm new to Ramda (and FP) and was hoping for some help with implementing some code with Ramda.

I have an object o with current value of { foo: [{ value: "bar" }] }.

I would like to create a function that appends an array of newData to one of the child arrays of existingData based on a dynamic criteria (in this case, I just take the first key of existingData).

Without Ramda, it looks like this:

const o = { foo: [{ value: "bar" }] };
function pushToFirstKey(newData, existingData) {
const key = Object.keys(existingData)[0]
return {
...existingData,
[key]: [...existingData[key], ...newData]
}
}
pushToFirstKey([{ value: "baz" }], o);
// Result: {"foo": [{"value": "bar"}, {"value": "baz"}]}

My attempt with Ramda looks like this:

const o = { foo: [{ value: "bar" }] };
const pushToFirstKeyFP = (newData, existingData) =>
R.compose(
)(newData);
pushToFirstKeyFP([{ value: "baz" }], o);
// Result: {"foo": [{"value": "bar"}, {"value": "baz"}]}

Which I suspect could be better written.

Does anyone have suggestions for me?

zrn
@zrn:matrix.org
[m]
it is kind of strange that you named parameters somethingData, when first is shape of [{}] and second is a different shape {[{}]}.
you can use modify like this:
const mergeArraysAtFirstKey = (arr, obj) => (
concat(arr))
);
also make sure that you actually know what first key will be, if there are keys that could be converted to number then they would be first
Justin Carrus
@jcarrus
@zrn:matrix.org ahh, thanks! That is much cleaner! And yes, good point on my naming. This was really helpful
zrn
@zrn:matrix.org
[m]

I should have mentioned that this is just for illustration, I wanted to understand how exactly it works, so optimisations like that wouldn't work in my case.

I also didn't hope to get any answer after so long, since then for my case I also considered generators, but they have overhead and are slower when entire collection must be computed. What is the performance price of using transducers? They look a bit like generators, object that has a function. So I guess it could be same as generators.

zrn
@zrn:matrix.org
[m]
I think I made a different design so I don't need to solve exactly this problem, still I hope I understood right how transducers work. But I want to know how they perform and when should they be used and when they should not be used.
The Very Angry Caterpillar

I don't know if this is useful information, but I found an example where R.flatten() on an array of objects with a length property does not work as intended.

https://ramdajs.com/repl/?v=0.28.0#?const%20obj%20%3D%20%7B%20length%3A%200%20%7D%0Aconst%20array1%20%3D%20%5B%20obj%2C%20obj%2C%20obj%20%5D%0Aconst%20array2%20%3D%20%5B%20array1%2C%20array1%2C%20%5B%20array1%2C%20array1%20%5D%2C%20array1%2C%20array1%5D%0A%0Aconsole.log%28R.flatten%28array2%29%29%0Aconsole.log%28array2.flat%282%29%29

In this example, R.flatten(array) and array.flat() produce different results.
This behavior is probably due to the fact that in the implementation of _isArrayLike(), an object with a length property of 0 is considered an array.
(I found this while using CodeMirror; CodeMirror's Line object has a length property which signifies how many chars the Line has.)

zrn
@zrn:matrix.org
[m]
idk if ramda should do exactly as normal js methods, map doesn't work exactly like method because of index parameter.
if (x.length === 0) { return true; } there is specific case for such object which makes it array like so I guess it works as intended.
I think it makes sense, we have {0: 'a', length: 1} this is array like, same "array" with zero items should look like {length: 0}
[pihentagy]
@pihentagy:matrix.org
[m]
zrn
@zrn:matrix.org
[m]
I think whole ramda doesnt work with iterators
Chuánqí Sun
@chuanqisun
Hi all, I'm new to Ramda and not proficient in FP. I saw Maybe.Just, Maybe.Of, and Maybe.Nothing in the documentation but not explained anywhere. Could anyone help point out what they are in JavaScript context and/or where I can learn about them?

Hi, I would like to know how to make a check inside the pipelines to avoid the process to throw exception.
For example:

const isTypeDensity = R.propEq('type', 'density');

const getDensity = R.pipe(
R.find(isTypeDensity),
R.pick(['value', 'error', 'measureUnit'])
)

when I pass a null argument to getDenisty it will throw an error but also if i pass an empty array (or an array with all alements that don't match the predicate) will throw an error because R.pick will take a null value. How can i fix this issue?
with vanilla javascript i can easily do with something like this:
myArray?.find()?. etc..

thank you for the help.

zrn
@zrn:matrix.org
[m]

you should somehow stop when find is undefined, there is no reason to do the pick at that point

const isTypeDensity = R.propEq('type', 'density');

const data = [{type: 'density', value: '1'}];
const wrongData = [{type: 'abc'}]

const density = //find(isTypeDensity, data);
find(isTypeDensity, wrongData);

const userPick = pick(['value', 'error', 'measureUnit']);

ifElse(identity, userPick, F)(density);

so something like this works, I can't say that I like it.
it is also not clear what u want returned when it fails.

zrn
@zrn:matrix.org
[m]

:point_up: Edit: you should somehow stop when find is undefined, there is no reason to do the pick at that point

const isTypeDensity = R.propEq('type', 'density');

const data = [{type: 'density', value: '1'}];
const wrongData = [{type: 'abc'}]

const density = //find(isTypeDensity, data);
find(isTypeDensity, wrongData);

const userPick = pick(['value', 'error', 'measureUnit']);

ifElse(identity, userPick, F)(density);
// or
when(identity, userPick)(density);

so something like this works, I can't say that I like it.
it is also not clear what u want returned when it fails.

Timar
@sugoidesune
Spent some prototyping a Ramdaa DataObject where you can endlessly chain functions where transformers automatically are transduced. Anyone find that interesting?
var data_array = [1, 2, 3,'hot', 4, 5, 6]
var D = x=> new Dataflow()

var data = D()
.filter(Number.isInteger)
.filter(x => x % 2)
.map(x => x * 2)
// these two filters and map get transduced automagically
.append('test')
.filter(x=> x>3)
.map(x => x * 2)
// filter + map = separate transducer
.prepend('maroon')
.compute(data_array)
// [ 'maroon', 5 ]
Timar
@sugoidesune
If someone wants to play around, proof of concept: https://replit.com/@TimarIvo/ramda-data-flow#index.js
Swen Mulderij
@Swendude

Hello everyone, I'm using Ramda with TS and can't get the mapping of objects to work:

const double = (x: number) => x * 2;

R.map(double, { aKey: 1 });

Complains that no overload can be found:

No overload matches this call.
Overload 1 of 6, '(fn: (x: number) => number, list: readonly number[]): number[]', gave the following error.
Argument of type '{ aKey: number; }' is not assignable to parameter of type 'readonly number[]'.
Object literal may only specify known properties, and 'aKey' does not exist in type 'readonly number[]'.
Overload 2 of 6, '(fn: (x: number) => never, list: { aKey: number; }): unknown', gave the following error.
Argument of type '(x: number) => number' is not assignable to parameter of type '(x: number) => never'.
Type 'number' is not assignable to type 'never'.
Overload 3 of 6, '(fn: (x: number) => number, obj: Functor<number>): Functor<number>', gave the following error.
Argument of type '{ aKey: number; }' is not assignable to parameter of type 'Functor<number>'.
Property 'map' is missing in type '{ aKey: number; }' but required in type '{ [key: string]: any; map: <B>(fn: (a: number) => B) => Functor<B>; }'.ts(2769)
What am I doing wrong?
Matt Diamond
@mattdiamond
@Swendude it's possible that the Ramda types from DefinitelyTyped are incorrect
Matt Diamond
@mattdiamond
you might just need to specify your input type as one of the generic parameters
Tom
@tofo_gitlab
It begs the question. Why use Ramda in TS. What are the gains?
I was wondering whether it might be good to add an equivalent function that python has. sorted(). In python it's a simple general purpose non mutating sort function. Could make things a little easier to have in in Ramda. better than Array.prototype.sorted = function() {return [...this].sort()} or const sorted = a = > [...a].sort()
Johan Apolinario Véliz
@johan-apo
I am starting my journey learning FP with JS. I have a newbie question. Can anything on OOP be coded using FP?
silently
@silently

hello, for guitar players I wanted to share a front-end project I made with ramda (and react): https://silently.github.io/cocotte/

this app iterates on the guitar fretboard to find playable chord voicing (see how ramda is used here for instance: https://github.com/silently/cocotte/blob/main/src/domain/processors/fingering.ts)
Thanks for ramda!

(if you have some feedback don't hesitate opening an issue on the project)

3 replies
[pihentagy]
@pihentagy:matrix.org
[m]
Is there a ramda function, which applies a list of function to one argument?
Or should I misuse ap with a one element array?
const double = x => x*2;
const square = x => x*x;

R.whatever([double, square], 3) => // [6, 9]
3 replies
zrn
@zrn:matrix.org
[m]
map((f)=>f(3), [double, square]) that kind of works
Krupodorov Roman
@seeker1983
rows.map(
row => R.assoc("City", userCities[row.Email] || row["City"])(row)
)
2 replies
How can I rewrite this to remove row variable in mapping?
Ghost
@ghost~612e3c566da0373984846d4a
@seeker1983 converge, lift, ap, juxt, applySpec, Applicative (modify, propOr)
R.map(
R.lift(R.assoc("City"))(
R.either(
R.pipe(
R.prop("Email"),
R.prop(R.__, userCities)
),
R.prop("City")
),
R.identity
)
);