-
-
Save josgraha/117617069044ca053228734d7fd2a08f to your computer and use it in GitHub Desktop.
fun-with-compose created by josgraha - https://repl.it/NznS/2
This file contains hidden or 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 { append, compose, filter, flatten, isArray, join, map, prepend } = R | |
const { log } = console | |
// html markup functions | |
const UL = 'ul' | |
const LI = 'li' | |
const tagOpen = tag => `<${tag}>` | |
const tagClose = tag => `</${tag}>` | |
const tagHoc = tag => compose( | |
append(tagClose(tag)), | |
prepend(tagOpen(tag)) | |
) | |
const toUnorderedList = tagHoc(UL) | |
const toListItem = compose(join(''), tagHoc(LI)) | |
const newlines = lst => lst.join('\n'); | |
const PHOTO = 'photo' | |
const VIDEO = 'video' | |
const media = [ | |
{ name: 'saturday.jpg', type: PHOTO }, | |
{ name: 'sunday.jpg', type: PHOTO }, | |
{ name: 'my.mov', type: VIDEO }, | |
]; | |
const isPhoto = p => p.type == PHOTO; | |
const itemName = p => p.name | |
const photoItems = filter(isPhoto) | |
const itemNames = map(itemName) | |
// TODO: write a function `toListItems` that returns invokes toListItem for a list of strings | |
const toListItems = ??? | |
log(toListItems(['a', 'b', 'c'])) | |
// expected: [ '<li>a</li>', '<li>b</li>', '<li>c</li>' ] | |
// TODO: write a function `photoNames` that returns the names of the photo items using compose | |
const photoNames = ??? | |
log(photoNames(media)) | |
// expected: ['saturday.jpg', 'sunday.jpg'] | |
// TODO: write a function `photoListItems` that returns photo names as list items | |
const photoListItems = ??? | |
log(photoListItems(media)) | |
// expected: [ '<li>saturday.jpg</li>', '<li>sunday.jpg</li>' ] | |
// TODO: write a function `markup` that composes photoListItems with toUnorderedList with newlines | |
const markup = ??? | |
log(markup(media)) | |
// expected: | |
// <ul> | |
// <li>saturday.jpg</li> | |
// <li>sunday.jpg</li> | |
// </ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment