Here is my issue: I have two lists as follows: [(Float, Integer)] and [(String, Integer)]. Now I need to define a function that takes these two Lists and two Float values and returns a list of Strings. The two Float values correspond to a range given (min and max). I have to filter the first list so it only contains elements that are within the min and max range. Then, I need to use the filtered list and take it's Integer values, match them with the Integer values in the second list and return all the String values that match.
I have already defined a function for use as a filter condition that takes a (Float,Integer) and checks the Float value to see if it is within the given range.
And I have defined a function to take a (String,Integer) element and return the String.
I'm just having problems linking everything together, or maybe I am missing something!
You need (for example, there are different ways)
integersFromRange :: Float -> Float -> [(Float,Integer)] -> [Integer]
stringsFromInteger :: Integer -> [(String,Integer)] -> [String]
integersFromRange is basically map snd . filter condition, with condition constructed from the two Floats (you have that). stringsFromInteger could be implemented as map fst . filter condition. Then you combine the functions with
result = concatMap (`stringsFromInteger` stringList) (integerFromRange mini maxi floatList)
Using a set of Integers instead of a list would be more efficient since membership test in a Set is faster than in a list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With