![]() ![]() ![]() Specs are essentially laws and similar to “interfaces” in Java. The above picture shows all the specs and their dependencies. Libraries that want to provide features like Functors, Monads and so on, need to implement functions/classes that follow some specs in order to provide functionalities like they are in languages like Haskell.įantasyland specs is one of the prominent specs that explains how each JS functions/classes should behave. While JavaScript doesn’t provide many of the tools out-of-the-box, thankfully it has enough FP features that allows people to write libraries. In order to deal with all these challenges, fully Functional Programming languages like Haskell provides various tools and concepts from mathematics like “Monads”, “Functors” and so on out-of-the-box. If a function is taking multiple values but chaining can only pass a single value, how can we still make it part of a chain ( Hint: “ currying” and “higher-order functions”)?.How to ensure the data we pass to it is unchanged so that we can reuse the data elsewhere( Hint: Pure functions, immutability)?.How to ensure functions are truly “reusable” and can be reused anywhere, ( Hint: Pure functions, referential transparency)?.How can we handle Null Exceptions ( Hint: “Maybe” Monad)?.How can we handle if-else condition? ( Hint: “Either” Monad).If everything can be done by composing a set of functions. Functional Programmingįunctional Programming is a style of writing programs by simply composing a set of functions.Įssentially, FP asks us to wrap virtually everything in functions, write lots of small reusable functions and simply call them one after the other to get the result like: ( 3) or in a compose fashion, like: func1(func2(func3())).īut in order to actually write programs in this style, functions need to follow some rules and overcome some challenges like the ones mentioned below: The FP Challenges: In Part 1, you’ll learn Functional Programming basics, Currying, Pure Functions, “Fantasy-land” specs, “Functors”, “Monads”, “Maybe Monads” and “Either Monads” via couple of examples. ![]() Please Note: The emphasis in this blog is on WHY xyz feature is required than just WHAT xyz feature is. That’s why I thought of writing a post to make it easier to use FP techniques. But it’s hard to learn and many posts and tutorials don’t go into details like Monads, Applicative and so on and don’t seem to use practical examples to help us use powerful FP techniques on a daily basis. By rajaraodv Functional Programming In JavaScript - With Practical Examples (Part 1)įunctional Programming(FP) can change the way you program for the better. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |