This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A version with explicit references to arguments | |
const getLastUserDisplayName = () => { | |
return getAllUsers() | |
.then(users => R.last(users)) | |
.then(lastUser => lastUser.firstName) | |
.then(firstName => R.toUpper) | |
} | |
// A point-free equivalent | |
const getLastUserDisplayName = () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda') | |
const trace = value => { | |
console.log(value) | |
return value | |
} | |
const fastestCarPF = R.pipe( | |
R.sortBy(R.prop('horsepower')), | |
trace, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const trace = value => { | |
console.log(value) | |
return value | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda') | |
const fastestCarPF = R.pipe( | |
R.sortBy(R.prop('horsepower')), | |
R.last, | |
R.prop('name') | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda') | |
const fastestCar = cars => { | |
const sorted = R.sortBy(car => car.horsepower, cars) | |
console.log(sorted) | |
const fastest = R.last(sorted) | |
return fastest.name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda') | |
const fastestCar = cars => { | |
const sorted = R.sortBy(car => car.horsepower, cars) | |
const fastest = R.last(sorted) | |
return fastest.name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const selectedNames = users => | |
R.pipe( | |
R.map(R.unary(parseInt)), | |
R.map(R.flip(R.prop)(users)), | |
R.map(R.prop('name')) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const selectedNames = users => | |
R.pipe( | |
R.map(R.unary(parseInt)), | |
R.map(userId => users[userId]), | |
R.map(R.prop('name')) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda') | |
const selectedNames = users => selectedUserIds => { | |
return selectedUserIds | |
.map(R.unary(parseInt)) | |
.map(userId => users[userId]) | |
.map(R.prop('name')) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const namesOfSelectedUsers = users => selectedUserIds => { | |
return selectedUserIds | |
.map(userIdString => parseInt(userIdString)) | |
.map(userId => users[userId]) | |
.map(user => user.name) | |
} |
NewerOlder