This came to may mind over the weekend and I was curious to know exactly what is happening when one chains methods together like the below code:
const posts = [{}, {}, {}, ...]
posts
.filter(({ node }) => node.fields.slug !== '/about/')
.reverse()
.slice(0, 5)
Each of the Array.prototype
methods returns an array after transforming the data in some fashion. filter
& slice
are both returning copies of the original array with the prescribed transformation present. What I am curious to know is if JavaScript is performing some internal piping like I would see in elixir
. Each method requires an array to work, but not necessarily as an argument, I think.
I don't believe the above is similar to. I know that the first arg must be whatever is returned from the prior operation for the pipe operator to work in elixir
:
posts
|> filter(({ node }) => node.fields.slug !== '/about/')
|> reverse()
|> slice(0,5)
Wasn't sure where to look to better understand this so if you can point me in the right direction I'll go read up on it. I was just curious to know, thanks so much for the information.