Referential transparency means an expression can be replaced by its value without changing program behavior. The guarantee depends on predictable inputs, immutable state, and the absence of observable side effects such as I/O, mutation, filesystem access, or randomness. section 4.1.2
This property makes functional code composable: independently defined expressions can be swapped like Lego bricks because equivalent expressions produce the same outcome and do not depend on global or shared state. section 4.3.1 section 4.1.2
Composing a word-counting pipeline
A word-counting operation can be assembled from read, decode, split, and count functions: compose(count, split, decode, read). The composition clarifies the transformation pipeline, although reading the file remains an effectful boundary rather than a referentially transparent operation. section 4.3.1
Listing 4.6 countWordsInFile implemented with compose
const countWordsInFile = compose(
count,
split,
decode,
read
);
countWordsInFile('sample.txt'); // 9
Inspect the composed JavaScript implementation and its sample result. section 4.3.1








