Many a times, I've come across statements of the form X does/doesn't compose well.
I can remember few instances that I've read recently :
I want to understand the implications of composability in terms of designing/reading/writing code ? Examples would be nice.
Composition is one of the fundamental concepts in object-oriented programming. It describes a class that references one or more objects of other classes in instance variables. This allows you to model a has-a association between objects.
In the context of Vue applications, a "composable" is a function that leverages Vue's Composition API to encapsulate and reuse stateful logic.
"Composing" functions basically just means sticking two or more functions together to make a big function that combines their functionality in a useful way. Essentially, you define a sequence of functions and pipe the results of each one into the next, finally giving the result of the whole process. Clojure provides the comp
function to do this for you, you could do it by hand too.
Functions that you can chain with other functions in creative ways are more useful in general than functions that you can only call in certain conditions. For example, if we didn't have the last
function and only had the traditional Lisp list functions, we could easily define last
as (def last (comp first reverse))
. Look at that — we didn't even need to defn
or mention any arguments, because we're just piping the result of one function into another. This would not work if, for example, reverse
took the imperative route of modifying the sequence in-place. Macros are problematic as well because you can't pass them to functions like comp
or apply
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With