I can't make the javascript sample provided Brunno work, although the code illustrate pointfree idea (i.e. no arguments) clearly. So I use ramda.js to provide another example.
Say I need to find out the longest word in a sentence, given a string "Lorem ipsum dolor sit amet consectetur adipiscing elit"
I need output something like { word: 'consectetur', length: 11 }
If I use plain JS style code I will code like this, using a map and a reduce function
let str = 'Lorem ipsum dolor sit amet consectetur adipiscing elit'
let strArray = str.split(' ').map((item) => ({ word: item, length: item.length }))
let longest = strArray.reduce(
(max, cur) => (cur.length > max.length ? cur : max),
strArray[0])
console.log(longest)
With ramda I still use a map & a reduce but I will code like this
const R = require('ramda')
let longest = R.pipe(
R.split(' '),
R.map((item) => ({ word: item, length: item.length })),
R.reduce((max, cur) => (max.length > cur.length ? max : cur), { length: 0 })
)
let tmp = longest(str)
console.log(tmp)
I will argue that the gist of my ramda code is the pipe that chains my functions together and it makes my purpose more clearly. No need to create a temporary variable strArray
is a bonus (if I have more than 3 steps in the pipe then it will become a real bonus).