I have a Java like property text files with key value pairs. What are some good approaches for loading that data into haskell and then accessing it.
The file look likes:
XXXX=vvvvv
YYYY=uuuuu
I want to be able to access the “XXXX” key.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Exploring a few details ehird didn’t mention, and a slightly different approach:
I’ve expressed my solution to your problem as a fold: taking the list of lines in the file, and turning it into the desired map. Each
stepof the fold involves inspecting a single line, attempting to parse it into a key/value pair, and when successful, inserting it into the map.I’ve left
parseOptundefined; you could use an approach like ehird’sparseField, or whatever you like. Perhaps you would prefer to only parse specific options:Using the prefix testing approach isn’t always the best idea, though, if you have (for example) an option “XX” and an option “XXXX”. Play around and see what approach suits your data best. If you need high performance, look into using Data.Text instead of
Strings.