### Start local server
Source: https://github.com/ramda/ramda.github.io/blob/master/README.md
Start the local development server.
```bash
npm start
```
--------------------------------
### Install dependencies
Source: https://github.com/ramda/ramda.github.io/blob/master/README.md
Install the required project dependencies.
```bash
npm i
```
--------------------------------
### Start local server on custom port
Source: https://github.com/ramda/ramda.github.io/blob/master/README.md
Start the local development server on a specific port.
```bash
npm start -- -p 8081
```
--------------------------------
### Install Ramda Dependencies
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Install all necessary dependencies for Ramda, including those for running tests.
```bash
npm install
```
--------------------------------
### Install Mocha for Testing
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Install Mocha globally to run the Ramda test suite from the console.
```bash
npm install -g mocha
```
--------------------------------
### Initialize Node environment
Source: https://github.com/ramda/ramda.github.io/blob/master/README.md
Install and use the required Node version using nvm.
```bash
nvm install && nvm use
```
--------------------------------
### Install Testem for Browser Testing
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Install Testem globally to facilitate testing Ramda across different browsers and environments.
```bash
npm install -g testem
```
--------------------------------
### R.subtract Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Demonstrates the use of R.subtract for basic subtraction and with R.__ for partial application.
```javascript
R.subtract(10, 8); //=> 2
const minus5 = R.subtract(R.__, 5);
minus5(17); //=> 12
const complementaryAngle = R.subtract(90);
complementaryAngle(30); //=> 60
complementaryAngle(72); //=> 18
```
--------------------------------
### Run Ramda Tests with Testem
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Start Testem to run Ramda tests in the browser, with live reloading. Open the provided link in your browser.
```bash
testem
```
--------------------------------
### Install Ramda via npm
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/README.md
Use this command to add the Ramda package to your Node.js project.
```bash
$ npm install ramda
```
--------------------------------
### R.objOf Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates an object with a single key-value pair. Useful for transforming data structures.
```javascript
const matchPhrases = R.compose(
R.objOf('must'),
R.map(R.objOf('match_phrase'))
);
matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]}
```
--------------------------------
### Run Ramda Tests with Detailed Output
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Run the Ramda test suite after installing dependencies, providing detailed output.
```bash
npm test
```
--------------------------------
### Install Ramda via npm
Source: https://context7.com/ramda/ramda.github.io/llms.txt
Install Ramda using npm for Node.js applications. You can require the entire library or import individual functions to optimize bundle size.
```javascript
// Install via npm
// npm install ramda
// CommonJS require
const R = require('ramda');
// Import individual functions to reduce bundle size
const map = require('ramda/src/map');
const filter = require('ramda/src/filter');
// ES6 import
import * as R from 'ramda';
import { map, filter, compose } from 'ramda';
```
--------------------------------
### R.not Examples
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Demonstrates the behavior of R.not with different truthy and falsy values.
```javascript
R.not(true);
//=> false
R.not(false);
//=> true
R.not(0);
//=> true
R.not(1);
//=> false
```
--------------------------------
### R.of Examples
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a new instance of a constructor containing a value. Dispatches to fantasy-land/of or the constructor's of method, otherwise wraps in an array.
```javascript
R.of(Array, 42); //=> [42]
R.of(Array, [42]); //=> [[42]]
R.of(Maybe, 42); //=> Maybe.Just(42)
```
--------------------------------
### Import Ramda in Node.js
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Require the Ramda library after installation.
```javascript
const R = require('ramda');
```
--------------------------------
### R.sum Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Calculates the sum of all numbers in a list using R.sum.
```javascript
R.sum([2,4,6,8,100,1]); //=> 121
```
--------------------------------
### R.tail Examples
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns all elements except the first from a list or string. Handles empty lists and strings.
```javascript
R.tail([1, 2, 3]); //=> [2, 3]
R.tail([1, 2]); //=> [2]
R.tail([1]); //=> []
R.tail([]); //=> []
R.tail('abc'); //=> 'bc'
R.tail('ab'); //=> 'b'
R.tail('a'); //=> ''
R.tail(''); //=> ''
```
--------------------------------
### R.nthArg Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a function that returns its nth argument. Handles positive and negative indices.
```javascript
R.nthArg(1)('a', 'b', 'c'); //=> 'b'
R.nthArg(-1)('a', 'b', 'c'); //=> 'c'
```
--------------------------------
### Create Partial Ramda Build
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Use this command to create a custom Ramda build with only the specified functions, reducing file size. Requires Node.js and installed Ramda dependencies.
```bash
npm run --silent partial-build compose reduce filter > dist/ramda.custom.js
```
--------------------------------
### R.T Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
A constant function that always returns true, ignoring any arguments.
```javascript
R.T(); //=> true
```
--------------------------------
### Import Ramda Library and Use Identity Function
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Import the entire Ramda library and destructure the 'identity' function for use. This example demonstrates a common way to import and utilize Ramda functions.
```javascript
import * as R from 'ramda'
const {identity} = R
R.map(identity, [1, 2, 3])
```
--------------------------------
### R.swap Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Swaps elements at specified indices in a list, string, or object. Handles positive and negative indices.
```javascript
R.swap(0, 2, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['c', 'b', 'a', 'd', 'e', 'f']
R.swap(-1, 0, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['f', 'b', 'c', 'd', 'e', 'a']
R.swap('a', 'b', {a: 1, b: 2}); //=> {a: 2, b: 1}
R.swap(0, 2, 'foo'); //=> 'oof'
```
--------------------------------
### R.symmetricDifference Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Finds elements present in either list but not in both. Order of lists does not affect the result set.
```javascript
R.symmetricDifference([1,2,3,4], [7,6,5,4,3]); //=> [1,2,7,6,5]
R.symmetricDifference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5,1,2]
```
--------------------------------
### R.symmetricDifferenceWith Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Compares elements using a custom predicate to find the symmetric difference between two lists.
```javascript
const eqA = R.eqBy(R.prop('a'));
const l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}];
const l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}];
R.symmetricDifferenceWith(eqA, l1, l2); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
```
--------------------------------
### Calculate Total Quantity of Items
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/01-intro/SmallFunctions.md
Use R.compose to combine multiple functions, applying them from right to left. This example first plucks the 'quantity' from each line item and then sums these quantities.
```javascript
R.compose(R.reduce(R.add, 0), R.pluck('quantity'))(lineItems);
```
--------------------------------
### Check if List or String Starts With Prefix in Ramda
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Checks if a list starts with the provided sublist or if a string starts with the provided substring. Returns a boolean.
```javascript
R.startsWith('a', 'abc') //=> true R.startsWith('b', 'abc') //=> false R.startsWith(['a'], ['a', 'b', 'c']) //=> true R.startsWith(['b'], ['a', 'b', 'c']) //=> false
```
--------------------------------
### Build documentation
Source: https://github.com/ramda/ramda.github.io/blob/master/README.md
Rebuild the documentation HTML file.
```bash
make docs/index.html
```
--------------------------------
### startsWith
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Checks if a list or string starts with the provided sublist or substring.
```APIDOC
## startsWith
### Description
Checks if a list starts with the provided sublist. Similarly, checks if a string starts with the provided substring.
### Method
N/A (Function signature)
### Endpoint
N/A (Function signature)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
R.startsWith('a', 'abc') //=> true
R.startsWith('b', 'abc') //=> false
R.startsWith(['a'], ['a', 'b', 'c']) //=> true
R.startsWith(['b'], ['a', 'b', 'c']) //=> false
```
### Response
#### Success Response (200)
Boolean: Returns `true` if the list/string starts with the prefix, `false` otherwise.
#### Response Example
```json
{
"example": "true"
}
```
```
--------------------------------
### Get array length
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns the number of elements in the provided array.
```javascript
R.length([]); //=> 0 R.length([1, 2, 3]); //=> 3
```
--------------------------------
### Create a Partial Build
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/README.md
Generate a custom build containing only the specific functions required to reduce file size.
```bash
./scripts/build -- src/compose.js src/reduce.js src/filter.js > dist/ramda.custom.js
```
--------------------------------
### Build styles
Source: https://github.com/ramda/ramda.github.io/blob/master/README.md
Rebuild the main CSS file from Less sources.
```bash
make style.css
```
--------------------------------
### Building Ramda
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Run this command in your project's root directory to build Ramda. This process generates the 'es' and 'src' directories and updates the distribution files.
```bash
npm run build
```
--------------------------------
### Get the last element
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns the last element of a list or string, or undefined if empty.
```javascript
R.last([1, 2, 3]); //=> 3 R.last([1]); //=> 1 R.last([]); //=> undefined R.last('abc'); //=> 'c' R.last('a'); //=> 'a' R.last(''); //=> undefined
```
--------------------------------
### prepend
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns a new list with the given element at the front, followed by the contents of the list.
```APIDOC
## prepend
### Description
Returns a new list with the given element at the front, followed by the contents of the list.
### Parameters
#### Path Parameters
- **el** (Any) - Required - The item to add to the head of the output list.
- **list** (Array) - Required - The array to add to the tail of the output list.
### Response
- **Array** - A new array.
```
--------------------------------
### init
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns all but the last element of the given list or string.
```APIDOC
## init
### Description
Returns all but the last element of the given list or string.
### Method
N/A (Function)
### Endpoint
N/A (Function)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```javascript
R.init([1, 2, 3]);
```
### Response
#### Success Response (200)
- **Array** or **String**: The list or string without its last element.
#### Response Example
```json
[1, 2]
```
```
--------------------------------
### Prepend element to list
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns a new list with the given element at the front, followed by the contents of the list.
```javascript
R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum']
```
--------------------------------
### fromPairs
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates an object from a list of key-value pairs.
```APIDOC
## fromPairs
### Description
Creates a new object from a list key-value pairs. If a key appears in multiple pairs, the rightmost pair is included in the object.
### Method
N/A (Function)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```javascript
R.fromPairs([['a', 1], ['b', 2], ['c', 3]]);
```
### Response
#### Success Response (200)
An object with the key-value pairs.
#### Response Example
```json
{
"example": "{a: 1, b: 2, c: 3}"
}
```
```
--------------------------------
### partial
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a new function with some arguments pre-filled.
```APIDOC
## partial
### Description
Takes a function `f` and a list of arguments, and returns a function `g`. When applied, `g` returns the result of applying `f` to the arguments provided initially followed by the arguments provided to `g`.
### Method
N/A (Function)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```javascript
// Example usage would typically involve a function with multiple arguments
// const multiply = (a, b, c) => a * b * c;
// const partialMultiply = R.partial(multiply, [2, 3]);
// partialMultiply(4); //=> 24
```
### Response
#### Success Response (200)
Returns a function that accepts the remaining arguments.
#### Response Example
N/A
```
--------------------------------
### R.omit Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns a new object with specified properties omitted. Useful for creating partial copies.
```javascript
R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}
```
--------------------------------
### pickAll
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a new object with specified properties, including undefined for missing properties.
```APIDOC
## pickAll
### Description
Similar to `pick` except that this one includes a `key: undefined` pair for properties that don't exist.
### Method
N/A (Function signature)
### Endpoint
N/A (Function signature)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```javascript
// Example for pickAll would go here if provided in source
```
### Response
#### Success Response (200)
N/A (Function signature)
#### Response Example
N/A
```
--------------------------------
### R.nth Examples
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Retrieves the nth element from a list or string. Handles negative offsets and out-of-bounds indices.
```javascript
const list = ['foo', 'bar', 'baz', 'quux'];
R.nth(1, list); //=> 'bar'
R.nth(-1, list); //=> 'quux'
R.nth(-99, list); //=> undefined
R.nth(2, 'abc'); //=> 'c'
R.nth(3, 'abc'); //=> undefined
```
--------------------------------
### pick
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a new object with only the specified properties from the original object.
```APIDOC
## pick
### Description
Returns a partial copy of an object containing only the keys specified. If the key does not exist, the property is ignored.
### Method
N/A (Function signature)
### Endpoint
N/A (Function signature)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```javascript
R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1}
```
### Response
#### Success Response (200)
N/A (Function signature)
#### Response Example
N/A
```
--------------------------------
### Take elements while predicate holds
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns elements from the start of a collection as long as the predicate function returns true.
```javascript
const isNotFour = x => x !== 4; R.takeWhile(isNotFour, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3] R.takeWhile(x => x !== 'd' , 'Ramda'); //=> 'Ram'
```
--------------------------------
### Import Ramda in Deno
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Import Ramda directly from a remote URL in Deno.
```javascript
import * as R from "https://deno.land/x/ramda@v0.27.2/mod.ts";
```
```javascript
import * as R from "https://x.nest.land/ramda@0.27.2/mod.ts";
```
--------------------------------
### Generate Number Sequences with range
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Create a list of numbers from a start value (inclusive) to an end value (exclusive).
```javascript
R.range(1, 5); //=> [1, 2, 3, 4] R.range(1, 5.5); //=> [1, 2, 3, 4, 5] R.range(1.5, 5.5); //=> [1.5, 2.5, 3.5, 4.5]
```
--------------------------------
### apply
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Applies function fn to the argument list args.
```APIDOC
## apply
### Description
Applies function fn to the argument list args. This is useful for creating a fixed-arity function from a variadic function.
### Parameters
- **fn** (Function) - The function which will be called with args.
- **args** (Array) - The arguments to call fn with.
### Response
- **Returns** (Any) - The result, equivalent to fn(...args).
### Request Example
```javascript
const nums = [1, 2, 3, -99, 42, 6, 7];
R.apply(Math.max, nums); //=> 42
```
```
--------------------------------
### Get a property from an object
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Retrieves the value of a specified property from an object. Returns undefined if the property does not exist. Can be composed with other functions.
```javascript
R.prop('x', {x: 100}); //=> 100
R.prop('x', {}); //=> undefined
R.prop(0, [100]); //=> 100
R.compose(R.inc, R.prop('x'))({ x: 3 }) //=> 4
```
--------------------------------
### Run Ramda Tests with Mocha
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Execute the Ramda test suite using Mocha from the project's root directory.
```bash
mocha
```
--------------------------------
### Include Ramda in Browser
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/README.md
Load the library directly in the browser using script tags from local files or CDNs.
```html
```
```html
```
```html
```
```html
```
```html
```
```html
```
--------------------------------
### Get Type of Primitive Values
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Demonstrates `R.type` for primitive JavaScript types like Number, Boolean, String, Null, and Undefined.
```javascript
R.type(1); //=> "Number"
R.type(false); //=> "Boolean"
R.type('s'); //=> "String"
R.type(null); //=> "Null"
R.type([]); //=> "Array"
R.type(/[A-z]/); //=> "RegExp"
R.type(() => {}); //=> "Function"
R.type(async () => {}); //=> "AsyncFunction"
R.type(undefined); //=> "Undefined"
R.type(BigInt(123)); //=> "BigInt"
```
--------------------------------
### R.o Function Composition Example
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Composes two unary functions from right to left, with the rightmost function invoked with a single argument.
```javascript
const classyGreeting = name => "The name's " + name.last + ", " + name.first + " " + name.last;
const yellGreeting = R.o(R.toUpper, classyGreeting);
yellGreeting({first: 'James', last: 'Bond'}); //=> "THE NAME'S BOND, JAMES BOND"
R.o(R.multiply(10), R.add(10))(-4) //=> 60
```
--------------------------------
### Sequence with Maybe and Array
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Demonstrates R.sequence with Maybe and Array functors. It shows how to sequence operations within a Maybe context, resulting in Nothing if any element is Nothing. It also shows sequencing an Array with a Maybe, resulting in an Array of Maybes.
```javascript
R.sequence(Maybe.of, [Just(1), Just(2), Just(3)]); //=> Just([1, 2, 3])
R.sequence(Maybe.of, [Just(1), Just(2), Nothing()]); //=> Nothing()
R.sequence(R.of(Array), Just([1, 2, 3])); //=> [Just(1), Just(2), Just(3)]
R.sequence(R.of(Array), Nothing()); //=> [Nothing()]
```
--------------------------------
### Get Type of Object
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns the native type of a JavaScript value as a string. Handles various types including custom objects and built-in types.
```javascript
R.type({}); //=> "Object"
R.type(new Map); //=> "Map"
R.type(new Set); //=> "Set"
```
--------------------------------
### R.keysIn
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns an array of the object's own and prototype properties.
```APIDOC
## R.keysIn
### Description
Returns an array of the object's own and prototype properties.
### Method
N/A (Function)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```json
{
"example": "const F = function() { this.x = 'X'; }; F.prototype.y = 'Y'; const f = new F(); R.keysIn(f); //=> ['x', 'y']"
}
```
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
```
--------------------------------
### Apply pre- and post-processors to a function
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Chains a preprocessor and a postprocessor around a given function. Useful for transforming input and output of existing functions.
```javascript
const decodeChar = R.promap(s => s.charCodeAt(), String.fromCharCode, R.add(-8))
const decodeString = R.promap(R.split(''), R.join(''), R.map(decodeChar))
decodeString("ziuli") //=> "ramda"
```
--------------------------------
### Get the first element of a list or string
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Use R.head to retrieve the first element from a list or string. Returns undefined for empty lists or strings.
```javascript
R.head([1, 2, 3]); //=> 1
R.head([1]); //=> 1
R.head([]); //=> undefined
R.head('abc'); //=> 'a'
R.head('a'); //=> 'a'
R.head(''); //=> undefined
```
--------------------------------
### Pick properties, including undefined for missing ones
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Use `pickAll` to create a new object with specified properties. Unlike `pick`, it includes properties that do not exist in the source object with a value of `undefined`.
```javascript
R.pickAll(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
R.pickAll(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined}
```
--------------------------------
### Ramda Property Accessor
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/01-intro/Immutability.md
Ramda's equivalent to JavaScript field accessors, using `R.prop` to get a property value without mutating the object.
```javascript
var getName = R.prop('name');
getName(person); //=> "Fred"
// or
R.prop('name', person); //=> "Fred"
```
--------------------------------
### Non-Referentially Transparent Function Example
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/01-intro/ReferentialTransparency.md
This function is not referentially transparent because it modifies a global variable and its output depends on external state. Avoid such functions in functional programming.
```javascript
var counter = 0;
var incrBy = function(n) {
counter = counter + n;
return counter;
}
```
--------------------------------
### String Splitting, Joining, and Trimming
Source: https://context7.com/ramda/ramda.github.io/llms.txt
Basic string manipulation utilities for splitting, joining, and whitespace removal, useful in composition pipelines.
```javascript
R.split(',', 'a,b,c'); //=> ['a', 'b', 'c']
R.join('-', ['a', 'b', 'c']); //=> 'a-b-c'
R.trim(' hello '); //=> 'hello'
// Parse CSV line
const parseCSV = R.pipe(
R.trim,
R.split(','),
R.map(R.trim)
);
parseCSV(' a , b , c '); //=> ['a', 'b', 'c']
```
--------------------------------
### binary
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Wraps a function of any arity in a function that accepts exactly 2 parameters.
```APIDOC
## binary
### Description
Wraps a function of any arity (including nullary) in a function that accepts exactly 2 parameters. Any extraneous parameters will not be passed to the supplied function.
### Parameters
- **fn** (Function) - Required - The function to wrap.
### Response
- **Function** - A new function wrapping `fn` with an arity of 2.
### Request Example
```javascript
const takesThreeArgs = function(a, b, c) { return [a, b, c]; };
const takesTwoArgs = R.binary(takesThreeArgs);
takesTwoArgs(1, 2, 3); //=> [1, 2, undefined]
```
```
--------------------------------
### Get a nested property or a default value
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Use `pathOr` to safely retrieve a nested property from an object. If the path does not exist or the object is null, it returns the provided default value.
```javascript
R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"
```
--------------------------------
### Calculate Invoice Total
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/01-intro/SmallFunctions.md
Use R.reduce to aggregate values in an array into a single result. This example calculates the total cost of all line items by summing up the price * quantity for each item.
```javascript
R.reduce((total, item) => total + item.price * item.quantity, 0)(lineItems);
```
--------------------------------
### Importing Ramda ES6 Module in Browsers
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
To use the ES6 module in browsers, you need to include the contents of the 'es' directory. This import path assumes Ramda is installed in your node_modules directory.
```javascript
import * as R from './node_modules/ramda/es/index.js';
```
--------------------------------
### unapply
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Takes a function `fn`, which takes a single array argument, and returns a function which takes any number of positional arguments, passes them to `fn` as an array, and returns the result.
```APIDOC
## unapply
### Description
Takes a function `fn`, which takes a single array argument, and returns a function which:
* takes any number of positional arguments;
* passes these arguments to `fn` as an array; and
* returns the result.
In other words, `R.unapply` derives a variadic function from a function which takes an array. `R.unapply` is the inverse of [`R.apply`](#apply).
### Method
`unapply`
### Endpoint
N/A (Function signature)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]'
```
### Response
#### Success Response (200)
N/A (Function return value)
#### Response Example
N/A
```
--------------------------------
### Project properties from objects
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Projects specified properties from a list of objects. Useful for selecting specific fields from a dataset.
```javascript
const abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2};
const fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7};
const kids = [abby, fred];
R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}]
```
--------------------------------
### Remove a sub-list with R.remove
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a new list with a specified number of elements removed, starting from a given index. This operation is not destructive and returns a copy of the original list with the elements removed.
```javascript
R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8]
```
--------------------------------
### Project Product ID and Quantity
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/01-intro/SmallFunctions.md
Use R.project to create new objects containing only specified properties from the original objects. This is useful for creating simplified data structures.
```javascript
R.project(['productId', 'quantity'])(lineItems);
```
--------------------------------
### Get all but the last element of a list or string
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Use `R.init` to return a new list or string containing all elements except the last one. Handles empty lists and strings correctly.
```javascript
R.init([1, 2, 3]); //=> [1, 2]
R.init([1, 2]); //=> [1]
R.init([1]); //=> []
R.init([]); //=> []
R.init('abc'); //=> 'ab'
R.init('ab'); //=> 'a'
R.init('a'); //=> ''
R.init(''); //=> ''
```
--------------------------------
### R.curry: Partial Application
Source: https://context7.com/ramda/ramda.github.io/llms.txt
Use R.curry to create curried functions for partial application. This allows creating reusable functions by pre-filling some arguments.
```javascript
const addThree = R.curry((a, b, c) => a + b + c);
// All equivalent ways to call:
addThree(1, 2, 3); //=> 6
addThree(1)(2)(3); //=> 6
addThree(1, 2)(3); //=> 6
addThree(1)(2, 3); //=> 6
// Create reusable partially applied functions
const add10 = addThree(10);
const add10And5 = add10(5);
add10And5(3); //=> 18
```
--------------------------------
### Filter Inexpensive Line Items
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/01-intro/SmallFunctions.md
Use R.filter to create a new array containing only the elements that satisfy a given condition. This example selects line items where the price is less than $10.00.
```javascript
R.filter(item => item.price < 10.00, lineItems);
```
--------------------------------
### Define Line Items Data
Source: https://github.com/ramda/ramda.github.io/blob/master/manual/01-intro/SmallFunctions.md
This JavaScript code defines an array of objects, each representing a line item with product details, price, and quantity. This data structure is used throughout the examples.
```javascript
var lineItems = [
{
productId: "783490",
description: "Rubik's Cube, 3x3x3",
price: 12.99,
quantity: 1
},
{
productId: "134672",
description: "Sudoku Book",
price: 6.50,
quantity: 3
},
{
productId: "162075",
description: "Sam Lloyd's 15 puzzle",
price: 3.25,
quantity: 5
},
];
```
--------------------------------
### R.head
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns the first element of a list or string.
```APIDOC
## R.head
### Description
Returns the first element of the given list or string.
### Parameters
- **list** (Array|String) - Required - The list or string to extract from.
### Response
- **Any|Undefined** - The first element or undefined if empty.
```
--------------------------------
### Bind Function Context with bind
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a function bound to a specific context. Does not support additional argument binding.
```javascript
const log = R.bind(console.log, console); R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3} // logs {a: 2}
```
--------------------------------
### Slice list or string
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Extracts a portion of a list or string using start and end indices. Negative indices are supported for counting from the end. `Infinity` can be used for the end index to slice to the end of the list.
```javascript
R.slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
R.slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd']
R.slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c']
R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
R.slice(0, 3, 'ramda'); //=> 'ram'
```
--------------------------------
### Merge objects with a custom key-based function
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Use `R.mergeWithKey` to combine two objects, applying a function that considers the key when merging values for common properties. This example concatenates 'values' arrays and uses the right-hand side value for other properties.
```javascript
let concatValues = (k, l, r) => k == 'values' ? R.concat(l, r) : r R.mergeWithKey(concatValues, { a: true, thing: 'foo', values: [10, 20] }, { b: true, thing: 'bar', values: [15, 35] }); //=> { a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] }
```
--------------------------------
### R.of
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a new instance of a constructor containing a value.
```APIDOC
## R.of
### Description
Given a constructor and a value, returns a new instance of that constructor containing the value. Dispatches to the `fantasy-land/of` method of the constructor first (if present) or to the `of` method last (if present). When neither are present, wraps the value in an array.
### Method
N/A (Function)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```javascript
R.of(Array, 42); //=> [42]
R.of(Array, [42]); //=> [[42]]
R.of(Maybe, 42); //=> Maybe.Just(42)
```
### Response
#### Success Response (200)
N/A (Function returns a new instance)
#### Response Example
N/A
```
--------------------------------
### Take elements from a collection
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns the first n elements of a list or string. Dispatches to a custom take method if available.
```javascript
R.take(1, ['foo', 'bar', 'baz']); //=> ['foo'] R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar'] R.take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] R.take(3, 'ramda'); //=> 'ram' const personnel = [ 'Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan', 'Bob Bates', 'Joe Dodge', 'Ron Crotty' ]; const takeFive = R.take(5); takeFive(personnel); //=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan']
```
--------------------------------
### zipObj: Create an object from keys and values lists
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Use `zipObj` to create an object by pairing elements from a list of keys with elements from a list of values. Pairing is truncated to the length of the shorter list.
```javascript
R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}
```
--------------------------------
### min
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns the smaller of its two arguments.
```APIDOC
## min
### Description
Returns the smaller of its two arguments.
### Parameters
- **a** (Ord a) - Required - First value.
- **b** (Ord a) - Required - Second value.
### Response
- **a** - The smaller of the two arguments.
```
--------------------------------
### splitWhen
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Takes a list and a predicate and returns a pair of lists.
```APIDOC
## splitWhen
### Description
Takes a list and a predicate and returns a pair of lists with the following properties:
- the result of concatenating the two output lists is equivalent to the input list;
- none of the elements of the first output list satisfies the predicate; and
- if the second output list is non-empty, its first element satisfies the predicate.
### Method
N/A (Function signature)
### Endpoint
N/A (Function signature)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]]
```
### Response
#### Success Response (200)
Array: A pair of lists split based on the predicate.
#### Response Example
```json
{
"example": "[[1], [2, 3, 1, 2, 3]]"
}
```
```
--------------------------------
### Run Ramda Tests Headlessly with Testem and PhantomJS
Source: https://github.com/ramda/ramda.github.io/blob/master/index.html
Execute Ramda tests headlessly using Testem and PhantomJS for automated testing environments.
```bash
testem -l phantomjs
```
--------------------------------
### tap
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Runs the given function with the supplied object, then returns the object.
```APIDOC
## tap
### Description
Runs the given function with the supplied object, then returns the object.
### Method
N/A (Function Signature)
### Endpoint
N/A (Function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
const sayX = x => console.log('x is ' + x);
R.tap(sayX, 100); //=> 100 // logs 'x is 100'
```
### Response
#### Success Response (200)
N/A (Function Return Value)
#### Response Example
```json
{
"example": "100"
}
```
```
--------------------------------
### zip: Pair up elements from two lists by index
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Use `zip` to create a new list by pairing elements at the same index from two input lists. The resulting list's length is determined by the shorter of the two input lists.
```javascript
R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]
```
--------------------------------
### String Splitting, Joining, and Trimming
Source: https://context7.com/ramda/ramda.github.io/llms.txt
Functions for basic string manipulation: splitting a string into an array, joining an array into a string, and removing whitespace from both ends of a string.
```APIDOC
## String Operations
### R.split, R.join, R.trim
### Description
String manipulation functions.
### Method
N/A (Pure function)
### Endpoint
N/A
### Parameters
N/A
### Request Example
```javascript
R.split(',', 'a,b,c'); //=> ['a', 'b', 'c']
R.join('-', ['a', 'b', 'c']); //=> 'a-b-c'
R.trim(' hello '); //=> 'hello'
// Parse CSV line
const parseCSV = R.pipe(
R.trim,
R.split(','),
R.map(R.trim)
);
parseCSV(' a , b , c '); //=> ['a', 'b', 'c']
```
### Response
N/A
```
--------------------------------
### R.useWith
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Accepts a function and a list of transformer functions and returns a new curried function.
```APIDOC
## R.useWith
### Description
Returns a new curried function. When invoked, it calls the function fn with parameters consisting of the result of calling each supplied handler on successive arguments to the new function.
### Parameters
- **fn** (Function) - Required - The function to wrap.
- **transformers** (Array) - Required - A list of transformer functions.
### Response
- **Returns** (Function) - The wrapped function.
```
--------------------------------
### R.objOf
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates an object with a single key-value pair.
```APIDOC
## R.objOf
### Description
Creates an object containing a single key:value pair.
### Method
N/A (Function)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```javascript
const matchPhrases = R.compose(
R.objOf('must'),
R.map(R.objOf('match_phrase'))
);
matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]}
```
### Response
#### Success Response (200)
N/A (Function returns an object)
#### Response Example
N/A
```
--------------------------------
### partialRight
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Takes a function `f` and a list of arguments, and returns a function `g`. When applied, `g` returns the result of applying `f` to the arguments provided to `g` followed by the arguments provided initially.
```APIDOC
## partialRight
### Description
Takes a function `f` and a list of arguments, and returns a function `g`. When applied, `g` returns the result of applying `f` to the arguments provided to `g` followed by the arguments provided initially.
### Parameters
* **f** - The function to partially apply.
* **args** - The list of arguments to apply to the right of the function's arguments.
### Returns
Function - A new function with pre-applied arguments.
### Example
```javascript
const greet = (salutation, title, firstName, lastName) =>
salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
const greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']);
greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!'
```
```
--------------------------------
### take
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Returns the first `n` elements of the given list, string, or transducer/transformer (or object with a `take` method).
```APIDOC
## take
### Description
Returns the first `n` elements of the given list, string, or transducer/transformer (or object with a `take` method).
### Method
N/A (Function Signature)
### Endpoint
N/A (Function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
R.take(1, ['foo', 'bar', 'baz']); //=> ['foo']
R.take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
R.take(3, 'ramda'); //=> 'ram'
```
### Response
#### Success Response (200)
N/A (Function Return Value)
#### Response Example
```json
{
"example": "['foo']"
}
```
```
--------------------------------
### Create a custom lens
Source: https://github.com/ramda/ramda.github.io/blob/master/docs/index.html
Creates a lens using provided getter and setter functions. The setter should not mutate the original data structure.
```javascript
const xLens = R.lens(R.prop('x'), R.assoc('x')); R.view(xLens, {x: 1, y: 2}); //=> 1 R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2}
```
--------------------------------
### List Combination R.zip and R.zipWith
Source: https://context7.com/ramda/ramda.github.io/llms.txt
Combine multiple lists into pairs or using a custom function.
```javascript
R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]
// Combine with custom function
R.zipWith(R.add, [1, 2, 3], [100, 200, 300]); //=> [101, 202, 303]
// Create objects from parallel arrays
const keys = ['name', 'age', 'city'];
const values = ['Alice', 30, 'NYC'];
R.zipObj(keys, values); //=> {name: 'Alice', age: 30, city: 'NYC'}
```