Skip to content

Instantly share code, notes, and snippets.

@BnayaZil
Created June 3, 2017 21:45
Show Gist options
  • Save BnayaZil/c70bac644e34256326149770efb96dfa to your computer and use it in GitHub Desktop.
Save BnayaZil/c70bac644e34256326149770efb96dfa to your computer and use it in GitHub Desktop.
Ramda series
import {prop, compose, apply, defaultTo, juxt, filter, gt, map} from 'ramda'
const players = [{
id: 1,
firstName: 'Bnaya',
age: 55,
file: {
img: 'http://foo.bar/bnaya-zil.png'
}
},
{
id: 2,
firstName: 'Leeor',
age: 10,
file: {
img: 'http://foo.bar/leeor-zil.png',
thumb: 'http://foo.bar/leeor-zil-thumb.png'
}
}]
const getFile = prop('file')
const getThumb = prop('thumb')
const getImg = prop('img')
const getAge = prop('age')
const getFileContent = juxt([getImg, getThumb])
const reduceFileContent = apply(defaultTo)
const getPlayerPicture = compose(reduceFileContent, getFileContent, getFile)
const getPlayersUnderFifty = filter(compose(gt(50), getAge))
const getPlyersUnderFiftyPicture = compose(map(getPlayerPicture), getPlayersUnderFifty)
const playerPicture = getPlyersUnderFiftyPicture(players) // returns: ['http://foo.bar/leeor-zil.png']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment