Skip to content

Instantly share code, notes, and snippets.

@bdesham
Created October 14, 2017 22:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdesham/b479fa89524914ff3d5e4a9f9f33f2ca to your computer and use it in GitHub Desktop.
Save bdesham/b479fa89524914ff3d5e4a9f9f33f2ca to your computer and use it in GitHub Desktop.
Adding a new key to the context based on a metadata key
-- | Creates a new field based on the item's metadata. If the metadata field is not present then no
-- field will actually be created. Otherwise, the value will be passed to the given function and the
-- result of that function will be used as the field's value.
transformedMetadataField :: String -> String -> (String -> String) -> Context a
transformedMetadataField key itemName f = field key $ \item -> do
fieldValue <- getMetadataField (itemIdentifier item) itemName
return $ maybe (fail $ "Value of " ++ itemName ++ " is missing") f fieldValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment