4 ms·
Haskell has a way of making the hard things easy and the easy things hard. The high level, pretty stuff is great. The ugly stuff is, for example, getting what w
by lambdasquirrel 14y ago
Haskell has a way of making the hard things easy and the easy things hard. The high level, pretty stuff is great. The ugly stuff is, for example, getting what we want out of `rawdata`.
You're probably thinking stuff like:
let list_usa = fmap (\row -> row^._4) $ filter (\row -> (row^._1)=="USA" ) rawdata
which is just saying, column 1 is the country, and we only want the rows that are "USA," and from those rows, we only want the fourth column. It would've been simpler if it were just arrays or lists, but that wouldn't be as powerful or as composable as lenses.
A better, more readable way would've been to not use those lambdas, since he's reusing the accessors over and over anyway:
let getKaboomieColumn row = row^._4
let trueIfUSA row = row^._1 == "USA"
let list_usa = fmap getKaboomieColumn $ filter trueIfUSA rawdata
...
When you read it that way, it looks a bit less intimidating.