A first-class function is a value that can be passed to another function, returned, named, stored in a data structure, or used to compute a new function. This makes reusable function composition central to declarative programming. section 1.2.2 section 8.3
Compose transformations
The composition operator applies its second function first and its first function second: (.) f g x = f (g x). Thus, f = (+1) . (*3) gives f 10 = 31. Functions can also be composed from a list, allowing a data structure to describe a reusable transformation pipeline. section 8.3
Listing 8.8 Functions to write CSV values to files
toFileContent :: Csv -> [T.Text]
toFileContent Csv {..} =
let rows = L.map (L.map dataFieldToText)
$ L.transpose csvColumns #1
in L.map (T.intercalate ",") $ #2
M.maybe rows (: rows) csvHeader #3
writeCsv :: FilePath -> Csv -> IO ()
writeCsv path = TIO.writeFile path .
T.intercalate "\n" . toFileContent #4
The CSV writer builds an IO action by composing functions that transpose columns, convert fields, intercalate rows, and write the resulting text to a file. section 8.3






