Some more practical examples // Grab unique [1,1,2,3,4].filter( ( item, index, array ) => array.indexOf( item ) === index ) // => [1,2,3,4] // Flatten [[1,2],[3,4]].reduce( ( result, item ) => result.concat(item), [] ); // => [1,2,3,4] Not sure why the author missed `sort`. // Sort [1,2,4,3].sort( ( a, b ) => a - b )
Javascript Arrays and Functional Programming
21–30 of 92 posts
Re: Javascript Arrays and Functional Programming
#22I accept that this is a widely used phrase now but I never understood why just using map/filter/reduce and avoiding state is enough for code to be called "functional programming". Most functional languages feature pattern matching, algebraic data types, purity, currying, strong typing, type inference, recursion instead of loops and types that cannot be null. It's a completely different style of coding. Adding map/fil…
Re: Javascript Arrays and Functional Programming
#23TL;DR author provides an example of map, filter and reduce functions in JS. I have been wondering lately what is the value of articles like this. They do not convey any meaningful idea, they do not offer any useful insight on underlying matters; why do people even write something like this, except to litter the Internet even more? Anyone, who is distinctly familiar with functional programming or even just with the co…
Re: Javascript Arrays and Functional Programming
#24I accept that this is a widely used phrase now but I never understood why just using map/filter/reduce and avoiding state is enough for code to be called "functional programming". Most functional languages feature pattern matching, algebraic data types, purity, currying, strong typing, type inference, recursion instead of loops and types that cannot be null. It's a completely different style of coding. Adding map/fil…
A better term would be "programming with functions as first class citizens", but many years ago that got shorted to "functional programming".
> Most functional languages feature pattern matching, algebraic data types, purity, currying, strong typing, type inference, recursion instead of loops and types that cannot be null.
That's a list of what many functional languages now contain, although most don't contain all of those. But that isn't the list of "common functional programming language features" from 10 years ago, and isn't necessarily what the list will be in 10 more years, either.
Re: Javascript Arrays and Functional Programming
#25Earlier quoted context omitted.
Wiki sums up the term well enough: "In computer science, functional programming is a programming paradigm — a style of building the structure and elements of computer programs — that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data." To that end map-reduce fits and can be referred to as 'functional programming'. The other things you mention are just great langu…
> The other things you mention are just great language features, but not specific to functional languages. Imperative C++ also has type safety, Swift has non-null types, etc. All those features in combination are shared by the vast majority of languages called functional programming languages. They're pretty much the defining features of functional languages was my point. Other languages can have a subset of the feat…
Clojure uses dynamic typing, yet it is still considered a functional language. I agree though that the combination of features results in a better experience when using functional primitives, but not having them doesn't mean this isn't functional programming still.
Re: Javascript Arrays and Functional Programming
#26TL;DR author provides an example of map, filter and reduce functions in JS. I have been wondering lately what is the value of articles like this. They do not convey any meaningful idea, they do not offer any useful insight on underlying matters; why do people even write something like this, except to litter the Internet even more? Anyone, who is distinctly familiar with functional programming or even just with the co…
It's like someone showing you multiplication and saying. See look how useful it is! See look how simple and easy it is to understand! I still don't know multiplication, or even addition for that matter.
Map and reduce are things you build up to by doing recursive functions over and over again. They are not something you learn from reading an article. Just like you can't read an article and suddenly know how to solve problems with long division.
Re: Javascript Arrays and Functional Programming
#27Some more practical examples // Grab unique [1,1,2,3,4].filter( ( item, index, array ) => array.indexOf( item ) === index ) // => [1,2,3,4] // Flatten [[1,2],[3,4]].reduce( ( result, item ) => result.concat(item), [] ); // => [1,2,3,4] Not sure why the author missed `sort`. // Sort [1,2,4,3].sort( ( a, b ) => a - b )
The first is slow (O(n²) where O(n) will do), and the second is very likely to be slow (probably the same).
Re: Javascript Arrays and Functional Programming
#28Re: Javascript Arrays and Functional Programming
#29TL;DR author provides an example of map, filter and reduce functions in JS. I have been wondering lately what is the value of articles like this. They do not convey any meaningful idea, they do not offer any useful insight on underlying matters; why do people even write something like this, except to litter the Internet even more? Anyone, who is distinctly familiar with functional programming or even just with the co…
Man, I had just worked up the nerve to start a personal dev blog but you've just scared me straight off.
Re: Javascript Arrays and Functional Programming
#30TL;DR author provides an example of map, filter and reduce functions in JS. I have been wondering lately what is the value of articles like this. They do not convey any meaningful idea, they do not offer any useful insight on underlying matters; why do people even write something like this, except to litter the Internet even more? Anyone, who is distinctly familiar with functional programming or even just with the co…
Man, I had just worked up the nerve to start a personal dev blog but you've just scared me straight off.
(It's unlikely it'll benefit arkadiytehgraet, but he probably finds that with a great many things.)