Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2017 17:34
Show Gist options
  • Save anonymous/ca8db762e5559c8cb7622ecc5decb322 to your computer and use it in GitHub Desktop.
Save anonymous/ca8db762e5559c8cb7622ecc5decb322 to your computer and use it in GitHub Desktop.
fun-with-compose created by josgraha - https://repl.it/NznS/2
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