Created
June 3, 2017 21:45
-
-
Save BnayaZil/c70bac644e34256326149770efb96dfa to your computer and use it in GitHub Desktop.
Ramda series
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
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