Skip to content

Instantly share code, notes, and snippets.

View krzysztofczernek's full-sized avatar

Krzysztof Czernek krzysztofczernek

View GitHub Profile
// 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 = () => {
const R = require('ramda')
const trace = value => {
console.log(value)
return value
}
const fastestCarPF = R.pipe(
R.sortBy(R.prop('horsepower')),
trace,
const trace = value => {
console.log(value)
return value
}
const R = require('ramda')
const fastestCarPF = R.pipe(
R.sortBy(R.prop('horsepower')),
R.last,
R.prop('name')
)
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
}
const R = require('ramda')
const fastestCar = cars => {
const sorted = R.sortBy(car => car.horsepower, cars)
const fastest = R.last(sorted)
return fastest.name
}
const selectedNames = users =>
R.pipe(
R.map(R.unary(parseInt)),
R.map(R.flip(R.prop)(users)),
R.map(R.prop('name'))
)
const selectedNames = users =>
R.pipe(
R.map(R.unary(parseInt)),
R.map(userId => users[userId]),
R.map(R.prop('name'))
)
const R = require('ramda')
const selectedNames = users => selectedUserIds => {
return selectedUserIds
.map(R.unary(parseInt))
.map(userId => users[userId])
.map(R.prop('name'))
}
const namesOfSelectedUsers = users => selectedUserIds => {
return selectedUserIds
.map(userIdString => parseInt(userIdString))
.map(userId => users[userId])
.map(user => user.name)
}