Ramda Thinking: Conclusion
- Transfer
- Tutorial
1. First steps
2. We combine functions
3. Partial application (currying)
4. Declarative programming
5. Pointless notation
6. Non-changeability and objects
7. Non-changeable and arrays
8. Lenses
9. Conclusion
This post completes a series of articles on functional programming called Ramda Thinking.
In the last eight posts, we’ve talked about the Ramda JavaScript library, which provides functions for working with JavaScript in a functional, declarative, and immutable style.
During this series of articles, we learned that Ramda has several basic principles that guide its API:
- The data comes last: almost all functions take a parameter with the data as the last argument.
- Currying: almost every feature in Ramda is “curried”. That is, you can call a function with only a part of the required arguments, and get a new function that will wait for the remaining arguments. As soon as all arguments are provided, the original function will be called.
These two principles allow us to write very clean functional code that combines basic building blocks into more powerful operations.
Summary
For reference, here is a short summary of a series of articles.
- The first steps represent the idea of functions, pure functions and immobility. Next, it introduces us to the functions of iteration over collections, such as
map
,filter
andreduce
. - Combining functions shows us how we can combine our functions in different ways, using tools such as
both
,either
,pipe
andcompose
. - Partial application (currying) helps us understand when and how it can be useful to provide some function arguments and to be able to provide the rest later. We use
partial
andcurry
to help us with this and learn aboutflip
and placeholder (__
) - Declarative programming teaches us the difference between imperative and declarative programming. We learn how to use Ramda declarative substitutes for arithmetic, comparisons, logic and conditions.
- The pointless notation introduces the idea of a pointless style, also known as "silent programming". In the bestechechnom style, we do not see the arguments with the data with which we work, it is done implicitly. Our programs are made up of small simple blocks that come together to do what we need. Only at the very end do we apply our component functions to actual data.
- Immutability and objects return us to the idea of working in a declarative style; this is the time to get the tools you need to read, update, change, delete, and transform the properties of objects.
- The immutability and arrays continues the theme and shows us how to do similar operations with arrays.
- The lenses complete the series along with a vision of the lens concept, a design that allows us to focus on small parts of large data structures. Using functions
view
,set
andover
, we can read, update and transform the value that the lens is focused on in the context of large data structures.
What's next?
We did not cover all the details of Ramda in this series of articles. In particular, we did not talk about functions for working with strings and did not talk about more complex concepts, such as transducers .
In order to learn more about what Ramda can do, I recommend studying its documentation . There is a wealth of information. All functions are grouped by the type of data with which they work, although there is some overlap. For example, some of the functions for working with arrays also work with strings, and map
work with both arrays and objects.
If you are interested in more complex functional topics, here are some places you can refer to:
- Transducers: here you can read a good introductory article on how to parse logs with the help of transducers.
- Algebraic data types: if you have read enough about functional programming, you have heard of algebraic types and such terms as "Functor", "Applicator" and "Monad". If you are interested in exploring these ideas in the context of Ramda, pay attention to the ramda-fantasy project , which implements some data types that conform to the Fantasy Land specification (or Algebraic JavaScript Specification)
From the author of translation of articles: if the Lord pleases, I will continue to translate articles on Ramda, in particular, I have a desire to translate an article on using ramda with redux , an article on functional components with React stateless functions and Ramda , an article on modular reducers and selectors , and probably an article on the globalization of redux selectors .
Only registered users can participate in the survey. Sign in , please.