Created
October 14, 2017 22:05
-
-
Save bdesham/b479fa89524914ff3d5e4a9f9f33f2ca to your computer and use it in GitHub Desktop.
Adding a new key to the context based on a metadata key
This file contains 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
-- | 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