4 ms·
Loved the explanation of Composition.
by sanatgersappa 12y ago
Loved the explanation of Composition.
- platz 12y ago> An often better alternative to chaining is composition It's not explained, but one of the reasons why is that function composition refactors more easily than chained code. The first operand (i.e. the value) in the chained code alters the semantics of all the subsequent chained code. You cannot replace parts of the chain as easy as you can with vanilla function composition; you always have that first value to worry about, and this reduces reusability slightly (compared to composition)
- deleted 12y ago[deleted]
- RobotCaleb 12y agoSame, but I feel like I'm missing something with one of the examples. squareIsOdd = square >> isEven >> not -- `not` is a built-in function that inverts booleans squareIsOdd 3 == True squareIsOdd 7 == False <-- huh?
- joshschreuder 12y agoYeah I didn't get that either, shouldn't that be False both times? 3^2 = 9 and 7^2 = 49, both odd.
- lsjroberts 12y agoHah, woops. Author here, I switched between odd and even and forgot to update the numbers... I'll fix it.
- lsjroberts 12y agoThanks :)