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
1 answer

Ramda's transducers: Lazy one-to-many branch

Ramda for the lazy Ramda's transduce enables the creation of lazy sequences. One to many R.chain can be used in a transducer as a one-to-many operator, like so (REPL): const tapLog = R.tap( (what) => console.log(what) ) const suits = ['♠', '♥',…
Izhaki
  • 23,372
  • 9
  • 69
  • 107
5
votes
1 answer

Selenium's driver.get() does not work under function composition

Calling driver.get(url) causes errors when I try to compose it with other functions. Here are my small functional methods: const webdriver = require('selenium-webdriver'); const By = webdriver.By; const R = require('ramda'); // Load…
haz
  • 2,034
  • 4
  • 28
  • 52
5
votes
2 answers

How can I map over object values using Ramda.js and take only first element?

I have input like that: { a: [obj1, obj2, obj3...], b: [obj1, obj2, obj3...], c: [obj1, obj2, obj3...] } I want to have that output (only first object from array for every key) { a: [obj1], b: [obj1], c: [obj1] } I want to do it using…
John Taylor
  • 729
  • 3
  • 11
  • 22
5
votes
4 answers

ramda.js: obtain a set of duplicates from an array of objects using specific properties

Given this array, containing javascript objects (json): Each object has a bproperty, and a u property, (each contains additional properties I am not concerned with for this exercise). [ { "b": "A", "u": "F", ... }, { "b": "M", "u": "T", ...…
Jim
  • 14,952
  • 15
  • 80
  • 167
5
votes
2 answers

Reverse arguments order in curried function (ramda js)

I have a higher order function: let's say for simplicity const divideLeftToRight = x => y => x/y; I would like to have a function that performs the division but from 'right to left'. In other words, I need to have: const divideRightToLeft = x => y…
tcoder01
  • 159
  • 1
  • 2
  • 7
5
votes
2 answers

Combining Maybe and IO monads for DOM read/write

I'm trying to cook up a simple example using IO and Maybe monads. The program reads a node from the DOM and writes some innerHTML to it. What I'm hung up on is the combination of IO and Maybe, e.g. IO (Maybe NodeList). How do I short circuit or…
Will M
  • 2,135
  • 4
  • 22
  • 32
5
votes
5 answers

Javascript: How can I replace nested if/else with a more functional pattern?

The following pattern gets repeated in my React app codebase quite a bit: const {items, loading} = this.props const elem = loading ? : items.length ? : While this is certainly cleaner than…
Kevin Whitaker
  • 12,435
  • 12
  • 51
  • 89
5
votes
1 answer

type checking helper with Ramda

I want to write a function whose specifications is described in the piece of code below which is the current implementation I have. It does work. However I have been trying for a while to write it pointfree and entirely as a composition of ramda…
user3743222
  • 18,345
  • 5
  • 69
  • 75
5
votes
3 answers

How do I pass in multiple parameters into a Ramda compose chain?

Here are four functions I am trying to compose into a single endpoint string: const endpoint = str => `${str}` || 'default' const protocol = str => `https://${str}` const params = str => `${str}?sort=desc&part=true&` const query = str =>…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
5
votes
1 answer

Monadic IO with ramda and ramda-fantasy

Trying to figure out how the IO monad works. Using the code below I read filenames.txt and use the results to rename files in the directory testfiles. This is obviously unfinished, so instead of actually renaming anything I log to console. :) My…
rickythefox
  • 6,601
  • 6
  • 40
  • 62
5
votes
1 answer

A function that can both compose and chain (dot notation) in Javascript

I'm trying to convert an old api that uses a lot of dot notation chaining which needs to be kept ie: [1,2,3,4].newSlice(1,2).add(1) // [3] I'd like to add the functional style of composition in this example Ramda but lodash or others would be…
cmdv
  • 1,693
  • 3
  • 15
  • 23
5
votes
2 answers

Transform objects pointfree style with Ramda

Given the function below, how do I convert it to point-free style? Would be nice to use Ramda's prop and path and skip the data argument, but I just can't figure out the proper syntax. const mapToOtherFormat = (data) => ( { 'Name':…
rickythefox
  • 6,601
  • 6
  • 40
  • 62
5
votes
5 answers

Get every possible combination of elements

How would you get every possible combination of 2 elements in an array? For example: [ 1, 2, 3, 4 ] becomes [ [1, 2], [1, 3], [1, 4], [2, 1], [2, 3], [2, 4], [3, 1], [3, 2], [3, 4], …
sa555
  • 320
  • 1
  • 4
  • 12
5
votes
3 answers

Ramda Js: Setting property on an object using a value from the same object

Using Ramda Js, I need to create a function that can set one object property using the value of a different property on the same object. My attempt so far is as follows: var foo = R.set(R.lensProp('bar'), 'foo' + R.prop('foo')); var result =…
James Flight
  • 1,424
  • 1
  • 13
  • 21
5
votes
2 answers

How to merge 2 compositions with Ramda.js

I have a string that I'm converting: "replace-me-correctly" => "Replace me correctly" my code using Ramda.js: const _ = R; //converting Ramda.js to use _ const replaceTail = _.compose(_.replace(/-/g, ' '), _.tail); const upperHead =…
cmdv
  • 1,693
  • 3
  • 15
  • 23