i’m trying to select some lists from a list when a condition is true, something like this:
I’ve made a data structure -> data File = File {name :: String, size :: Integer, comment :: String} deriving Show
And i have already made a library with all the files following this structure:
files = [[“name1″,size1,”coment1”],[“name2″,size2,”coment2”],[“name3″,size3,”coment3”],…]
Now what i need is a function that selects me all the lists which the sizes are for example >= 500, something like
list = select ((>=500.size) files)
So if i had:
files = [["asd",345,"coment1"],["fgh",678,"coment2"],["hjk",123,"coment3"],...]
I would get:
list = [["fgh",678,"coment2"]]
Any help would be gladly appreciated.
Thanks in advance.
The Prelude contains the useful
which does what you intend your
selectto do.Answering your comment to Jon Purdy’s answer:
Aside:
won’t work, lists are homogeneous. It should in the context of the question be
Filehaving been defined with record-syntax, you can use it with record syntax or vanilla positional syntax, whatever is better in a given situation. Record syntax would be more typing than the above, but if you used it,files = [File{ name = "asd", size = 345, comment = "coment1" }, ... ]would continue to work if you added fields to the type – the added fields would then be instantiated withundefined, which may or may not be better than the code not compiling without changes.