Skip to content

Instantly share code, notes, and snippets.

@joshperry
Created August 9, 2018 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshperry/ad0a960c5c6f6c4298ba9f783587d761 to your computer and use it in GitHub Desktop.
Save joshperry/ad0a960c5c6f6c4298ba9f783587d761 to your computer and use it in GitHub Desktop.
// Grab the ComType tag
const getTag = (product, tag) =>
product.Tags
.split(',')
.find(t => t.startsWith(`${tag}=`))
.split('=')[1]
const keyMatches = key => compose(equals(Just(key)))(head)
const getTagf = (product, tag) =>
compose
(fromMaybe(Just(''))) // or provide an empty string
(tail) // Take the value
(find(keyMatches(tag))) // Find pair with matching key
(map(splitOn('='))) // Split KVPs
(splitOn(',')) // Split CSVs
(toMaybe(product.Tags)) // Take maybe null string of CSV KVPs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment