How you can use ES6 Arrow Functions to make your JavaScript easier to read
Tyler McGinnis

I’m confused about this pattern being used everywhere of chaining single line promises. I’m not able to decide how this is better

 .then(response => response.json())
.then(response =>
.then(tweets => tweets.filter(tweet => tweet.stars > 50))
.then(tweets => tweets.filter(tweet => tweet.rts > 50))

than just writing this

.then(response => { 
const tweets = response.json().data;
tweets = tweets.filter(tweet => tweet.stars > 50)
tweets = tweets.filter(tweet => tweet.stars > 50)

My thoughts:
1. First one represents how the data is transferred in an immutable way vs second mutates the data. Don’t see any issue with mutation there though.
2. Promises are meant to be use for asyn operations, so using it for just transforming the data seems misleading to me.

Like what you read? Give Rahul Gupta a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.