Questions tagged [ramda.js]

Ramda is a functional utility library for Javascript, focusing on making it easy to build modular pipelines out of small, composable functions.

Ramda is a functional utility library for Javascript, focusing on making it easy to build modular pipelines out of small, composable functions.

Functions in Ramda are curried, meaning that if called with fewer than the required number of parameters, they will simply return new (curried) functions that require the remaining ones. Parameter order is different than the native order or the order in libraries such as Underscore or LoDash; those parameters expected to change the most (generally the data being operated on) are supplied last.

Useful Links

1196 questions
5
votes
2 answers

Obtaining the largest item in a list using ramda

I am trying to return the largest element in a list page: page = [1,2,3]; R.max(page); // returns a function. R.max(-Infinity, page); // seems correct but doesn't work as expected.
Jim
  • 14,952
  • 15
  • 80
  • 167
5
votes
2 answers

Is there something similar to lodash _.toArray for ramda.js?

I want to stop using lodash.js and switch to ramda.js but I don't see any function like _.toArray() for objects, is there something like this in ramda that I should compose or should I continue using lodash for these functions (and possibly more…
simplesthing
  • 3,034
  • 3
  • 15
  • 16
5
votes
2 answers

Can I curry this better?

I've made this snippet using ramda to check if any value of array A exists in array B, assuming they are flat arrays. var hasAtLeastOneTruthValue = ramda.contains(true); var alpha = [1,2,3] var beta = [4,1,7]; var valueOfArrayInArray =…
rollingBalls
  • 1,808
  • 1
  • 14
  • 25
4
votes
2 answers

Point-free version of g(f(x)(y))

Is there a way to express the following in point-free form: g(f(x)(y)) It is not a common 'combinator' as far as I can see, though there are perhaps different ways to express it? I am working in Javascript with Ramda.
jramm
  • 6,415
  • 4
  • 34
  • 73
4
votes
2 answers

How to rewrite this ramda.js code in vanilla JS

I am removing ramda from some code I've inherited as part of an effort to reduce the JavaScript size. But I'm stuck with the below because this line really baffles me as it apparently doesn't operate on any object. var iterate =…
bytevic
  • 43
  • 5
4
votes
1 answer

Ramda remove nested null values

I want to remove all null values from a object. Let's suppose: const data = { key1: 'ok', key2: null, key3: '', // should be removed too key4: { inner_key1: 'aaa', inner_key2: null } } What I did was this const clean =…
Rodrigo
  • 135
  • 4
  • 45
  • 107
4
votes
2 answers

How to split an array into sublists with Ramda?

This is the initial state. const All = {   id : [ "a", "b", "c", "d", "e"], count : [1, 2, 2], } I want All.id split into [ ["a"], ["b", "c"], ["d", "e"]] by using the All.count I tried R.map(R.take(All.count), All.id). But this is not…
Rio
  • 123
  • 7
4
votes
1 answer

Transform an object with a new property derived from original properties in ramda

What is the easiest way to transform the following object? // original { name: "bob", age: 24 } // result { name: "bob", age: 24, description: "bob is 24 years old" } I can use lens to update a single property, such as…
user1164937
  • 1,979
  • 2
  • 21
  • 29
4
votes
0 answers

How to define Placeholder's type in Ramda in typescript?

const greet = R.replace('{name}', R.__, 'Hello, {name}!'); greet('Alice'); //=> 'Hello, Alice!' The above code is copy from Ramda's documment, when a pate it in typescript environment, typescript complains: Argument of type 'Placeholder' is not…
nolan
  • 439
  • 3
  • 13
4
votes
2 answers

Ramda: How can I filter data with nested objects?

const articles = [ {title: 'title 1', published: false, pages: 30, tags: {name: 'work', id: 1, visibility: "everyone"}}, {title: 'title 2', published: false, pages: 25, tags: {name: 'home', id: 3, visibility: "myself"}}, {title: 'title…
muskrat_
  • 101
  • 7
4
votes
1 answer

Ramda typescript is giving typescript compilation errors

Added @types/ramda Now I get typescript errors from @types/ramda Failed to compile. /Users/xx/WebstormProjects/xx/frontend/node_modules/@types/ramda/index.d.ts TypeScript error: ',' expected. TS1005 81 | * function: the current index, and the…
Joe
  • 4,274
  • 32
  • 95
  • 175
4
votes
4 answers

Ramda pipe conditionally?

I have a filter function which has essentially multiple variables that determine filtering logic. If the variable is defined, I want to filter—if not, I don't want to filter (i.e. execute the function in the pipeline). More generally, having a…
rb612
  • 5,280
  • 3
  • 30
  • 68
4
votes
2 answers

How to turn a list of objects into a keyed array/object?

I'm trying to write code using Ramda to produce a new data structure, using only the id and comment keys of the original objects. I'm new to Ramda and it's giving me some fits, although I have experience with what I think is similar coding with…
Mr. Lance E Sloan
  • 3,297
  • 5
  • 35
  • 50
4
votes
4 answers

Functional way of re-using variables in a pipe

Using functional programming in javascript and typescript together with Ramda, I often find myself writing code like: const myFun = c => { const myId = c.id const value = pipe( getAnotherOtherPropOfC, transformToArray, …
maxpower90
  • 75
  • 4
4
votes
1 answer

map behaviour with strings

given that map is: map :: (a -> b) -> [a] -> [b] why R.map(R.toUpper, 'hello') returns ['H', 'E', 'L', 'L', 'O'] and not "HELLO"? in haskell, for instance, a string is a list of chars, so map toUpper "hello" behaves as expected (HELLO). Shouldn't…
Hitmands
  • 13,491
  • 4
  • 34
  • 69