Function Composition - Functional JavaScript

preview_player
Показать описание
In this video, I explain function composition, using JavaScript. Function composition allows us to create new functions by combining existing functions together.

It might seem weird at first, but this is a common and powerful pattern in functional programming.

Рекомендации по теме
Комментарии
Автор

I never have gotten this much clear understanding regarding chain or compose

ummerzaman
Автор

Thanks for the video this has been very helpful to me.
Could I just mention that your compose function is really the function commonly known as "pipe" ie. left to right application of functions. To get a true compose function you would need to replace reduce with reduceRight which would give right to left application of functions.

const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x)

sweeball
Автор

Thank you for this, awesome explanation. I could understand some principles with plain JS without use libraries to do that. You rocks

caramujoloko
Автор

Nice video, now the question is: How do you make this type-safe with TS?

eidiazcas
Автор

It will more clear if you change the apply function param name fn1 to accumulator or something else because that is not function.

I was confused on that part.
Thank you for your Awesome video.

mishalrai
Автор

thank you! Very helpful! Keep up the good work! (:

artium