DEV Community 👩‍💻👨‍💻

Discussion on: You don't need classes

Collapse
 
nitsanavni profile image
Nitsan Avni

in this function:

const moveShape = ({ x, y }) => shape => ({ ...shape, x, y });
Enter fullscreen mode Exit fullscreen mode

why do we provide { x, y } first and then shape, and not the other way around?

Collapse
 
rommguy profile image
Guy Romm

Because the common use of such functions is to use the curried result as an argument to another function

So you would do this -
const moveByFive = moveShape({x: 5, y: 5})

Then you would do some operations on a shape or a collection of shapes

flow(
filter(shape => shape.x < 10),
moveByFive,
map(transformShape)
)(shapes)

Collapse
 
lukeshiru profile image
Luke Shiru Author

Thanks a lot @rommguy for taking the time to explain that. Great explanation btw! :D

Some comments have been hidden by the post's author - find out more