My Code Docs

My Code Docs

  • Docs
  • Projects
  • Components
  • Help

›JS/React Libs

Javascript

  • Promises and Asnyc/Await
  • Local Storage
  • Firebase
  • JS Language Basics
  • JS Array Functions
  • Keyboard and Mouse Input
  • ES6 Cheatsheet
  • ESLint Setup
  • Data Structures
  • Naming Conventions
  • Javascript Resources
  • Javascript Snippets
  • npm Module Creation

Node

  • Node JS Basics
  • Server Config and SSH

NextJS

  • NextJS Basics

JS/React Libs

  • Lodash Library
  • Axios
  • Ramda
  • Moment JS
  • Overmind
  • Redux Forms npm Module
  • React Beautiful DnD
  • Ant Design
  • Zustand State Managment

React

  • React Basics
  • React Hooks
  • React With Classes
  • Reach Router
  • React Router
  • React Components

Redux

  • Redux in React
  • My Redux Pattern
  • Redux with React (First Doc)
  • Simple Redux Package

ReactNative

  • React Native
  • React Navigation V5
  • React Navigation V4

HTMLCSS

  • HTML and CSS Snippets
  • Tailwind CSS

Electron

  • Electron React Boiler
  • Electron Basics
  • Electron Packaging
  • Electron Tooling

Ramda

Ramda Homepage Ramda Documentation Page

Why Ramda?

There are already several excellent libraries with a functional flavor. Typically, they are meant to be general-purpose toolkits, suitable for working in multiple paradigms. Ramda has a more focused goal. We wanted a library designed specifically for a functional programming style, one that makes it easy to create functional pipelines, one that never mutates user data.

Useful Ramda Functions

R.flatten(Arrays and/or Items)

Returns a new list by pulling every item out of it (and all its sub-arrays) and putting them in a new array, depth-first.

R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]);
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

R.pick([array of string keys], Object To copy from) -> returns new Object

Returns a partial copy of an object containing only the keys specified. If the key does not exist, the property is ignored.

let obj = {
  password: 'x',
  name: 'mark',
  lastName: 'mccoid',
  box: 1
};
console.log(R.pick(['lastName', 'name'], obj));
//returns:
//[object Object] {
//  lastName: "mccoid",
//  name: "mark"
//} 

R.omit([array of string keys], Object To copy from) -> returns new Object

Opposite of R.pick(). Returns a partial copy of an object omitting the keys specified.

R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}

R.path([path], Object To Look into)

Retrieve the value at a given path. This is useful, because instead of throwing an error if the path doesn't exist, you get undefined returned. Think of trying to get an Object property value that is nested, but that property doesn't have to exist. Path will just returned undefined. However, take a look at R.pathOr(), which will actually give you a default value back.

R.path(['a', 'b'], {a: {b: 2}}); //=> 2
R.path(['a', 'b'], {c: {b: 2}}); //=> undefined

R.pathOr(Default, [path], Object To Look into)

If the given, non-null object has a value at the given path, returns the value at that path. Otherwise returns the provided default value.

R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"

R.prop(Property To look for, Object To look in)

Returns a function that when supplied an object returns the indicated property of that object, if it exists. NOTE: Since this returns a function, it can be curried.

R.prop('x', {x: 100}); //=> 100
R.prop('x', {}); //=> undefined
//Or Curry style
let checkForx = R.prop('x');
console.log(checkForx({x: 100})) //=> 100

R.project([Props to Select], Array of Objects)

Reasonable analog to SQL select statement.

var abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2};
var fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7};
var kids = [abby, fred];
R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}]

R.pipe()

Performs left-to-right function composition. The leftmost function may have any arity; the remaining functions must be unary.

In some libraries this function is named sequence.

Note: The result of pipe is not automatically curried.

var f = R.pipe(Math.pow, R.negate, R.inc);

f(3, 4); // -(3^4) + 1

If you want to pass multiple values to the functions other than the first one, you will need to make sure that it returns a function that accepts what the previous function is going to "pipe" to it.

//Create a function that accepts x and then returns a function waiting for it's y value to be supplied.
powCurry = (x) => (y) => Math.pow(x,y)

f = R.pipe(Math.pow, powCurry(2), R.negate, R.inc);
console.log(f(2,2))
← AxiosMoment JS →
  • Useful Ramda Functions
    • R.pick([array of string keys], Object To copy from) -> returns new Object
    • R.omit([array of string keys], Object To copy from) -> returns new Object
    • R.path([path], Object To Look into)
    • R.pathOr(Default, [path], Object To Look into)
    • R.prop(Property To look for, Object To look in)
    • R.project([Props to Select], Array of Objects)
    • R.pipe()
My Code Docs
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2020 McCoidCo