<h1>Test of Ramda library</h1>
<h2>compose, pipe, map, sum</h2>
see console output.
// Ramda library test
// library "Rambda" (light version of Ramda) does not work for some reason ("R" not available)
"use strict";
let cout = console.info;
console.clear();

function a1(x) {
  return x+1;
}

function a2(x) {
  return x*2;
}

let pipedFunctions = R.pipe(a1, a2);
cout( pipedFunctions(8) ); // result is 18, SAME AS CALLING THIS:  a2(a1(8))

let composedFunctions = R.compose(a1, a2);
cout( composedFunctions(8) ); // a1(a2(8))   so result is 17

cout( R.compose(a1, a2)(10) ); // a1(a2(10))  so result is 21


// --- now something completely different, showcase of "map"

let cart = [
  {itemName: "laptop", price: 85},
  {itemName: "mouse", price: 5},
  {itemName: "keyboard", price: 10}
];

function getCartWithTax(item) {
  return {
    itemName: item.itemName,
    price: item.price * 1.2
  };
}

console.log( R.map(getCartWithTax, cart) );
//console.log( cart.map(getCartWithTax) ); // vanilla JS .map, identical result

function getTotalSumWithTax() {
  let totalSum = R.compose( R.sum, R.map );
  let getPricesOnly = (item) => item.price * 1.2;
  return totalSum(getPricesOnly, cart);
}

console.log( getTotalSumWithTax() );

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.min.js