![]() ![]() Pay attention to vocabulary - call your curried functions “curriedSomething” or as an ongoing process (like in this case, “reduction”). We have extended the example of reducing called “curriedReduce” (we can also call it “reduction”) - it means that you have to execute that function to end the process. Everything you need is a flat description of flow and proper declarations that express your control flow with the partial transmission of arguments: const curriedReduce = curry(reduce)(collection, reducer, accumulator) In the next part of the article, you can see we use that convention totally in all cases.įorget about “this”, “apply”, and “call” methods. For “filter”, “some”, “find”, and similar operations (using probably pure functions) we use predicate function called checker or just predicate: const fooChecker = () => Any const fooFiltered = filter( collection: Any, fooChecker, ) In the sort functions (“union”, “sort”), the invoke function per element is called a comparator. ![]() Now it’s time to use it more consciously and look for analogies in your code.įor a more “lexical” way, we can use it in our code as a suffix - then you always know what the role of each of the individual variables is: const fooReducer = (result: Any, current: Any) => Any const fooReduced = reduce( collection: Any, fooReducer, result, ) const fooMapper = () => Any const fooMapped = map( collection: Any, fooMapper, ) Let’s check implementations of reduction in Lodash and vanilla JS - as you can see, that that terminology is nothing innovative and you have probably seen it before. “Reduced” is an adjective and indicates that something has been completed - it is a result of our process. We also have an operator called “reducer” (or “iteratee”) - a noun, which means it’s a role that provides functionality to realize “reduce” operation, we called it operator function. Let’s start from “reduce” - the word is a verb which indicates an action, so it is an operation - a declaration with defined scopes per argument with all the information on what that function does. As you see, our composition includes target collection (also known as a functor because it is mappable), reducer (an operator function), and optional argument - in this case “accumulator”. ![]() The above scheme could be a base for most of your problems in a naming dilemma. Operations and operator functions const reduced = reduce(collection, reducer, accumulator) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |