Hacker News new | past | comments | ask | show | jobs | submit login

In Haskell there are two varieties on this. "Apply" and "compose":

          f (g (h x)) == f $ g $ h $ x
                      == f . g . h $ x
    \x -> f (g (h x)) == f . g . h
The "compose" combinator, (.), is especially pertinent for making pipelines. Idiomatic Haskell code uses it constantly---especially for its natural mechanism of eliminating "points" like that `x` above. These are usually better described by their type than any variable name given (especially since the variable name cannot be machine checked for meaningfulness, unlike the type) and so are best eliminated.

In many libraries there is also a reverse apply function defined, often as &

          f (g (h x)) == x & h & g & f
                      == x & f . g . h
which is more popular when using other operator chains to describe functions as in lens.



Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: