-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathramda-composition.js
42 lines (33 loc) · 953 Bytes
/
ramda-composition.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const R = require("ramda");
const lunchOptions = [
{
dishName: "Turkey Sandwich",
veggetarian: false
},
{
dishName: "Vegetable Sandwich",
veggetarian: true
},
{
dishName: "Tuna Sandwich",
veggetarian: false
}
];
// We want to extract all non vegetarian dish names
/* Imperative */
let nonVegeratianDishNames = [];
for (let options of lunchOptions) {
if (options.veggetarian === false) {
nonVegeratianDishNames.push(options.dishName);
}
}
nonVegeratianDishNames;
/* Declarative and functional */
const isNotVegeratian = option => R.not(option.veggetarian);
const nonVegeratianDishes = R.filter(isNotVegeratian); // data gets passed in last
const getDishName = R.pluck("dishName");
//const spacer = R.join(",");
// we can now clean it up a bit using some pipes (chaining)
const getNonVeggieDishNames = R.pipe(nonVegeratianDishes, getDishName);
const names = getNonVeggieDishNames(lunchOptions);
names;