have a function that is returning:
>>> ["Just (Number 8000.0)","Just (Number 93.0)","Just (String \"test\")"]
What is the best way to get just the values?
>>> ["8000.0", "93.0", "test"]
The code is trying to parse JSON, using prisms from Aeson.
Code
jsonFile :: FilePath jsonFile = "test.json" getJSON :: IO BS.ByteString getJSON = BS.readFile jsonFile main :: IO () main = do input <- getJSON print $ f input f :: BS.ByteString -> [String] f x = [ show $ (x ^? key "a" . nth 0 . key "b") , show $ x ^? key "a" . nth 0 . key "c" , show $ x ^? key "a" . nth 0 . key "d" ]
Maybe?Number,String, etc.?Maybe. Perhaps the function you have called mappedshowover your data?prismto obtain a particular value. so Number is an Int and String is a Stringshow $ ...withmaybe "Nothing" show $ ...? This still prints the string"Nothing"for any such values in the list, but prints theJustvalues without the"Just".