Created
August 9, 2018 01:23
-
-
Save joshperry/ad0a960c5c6f6c4298ba9f783587d761 to your computer and use it in GitHub Desktop.
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
// 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