I am delving into functional programming for the first time and have a query regarding using pipes.
Imagine I have this particular function:
const updateArray = R.curry((index, value, array) =>
Object.assign([], array, {[index]: value}))
This function alters the value of an element in an array based on a specified index.
Now, my goal is to utilize this function twice (using pipe) to create a swap functionality between two elements in the array.
However, I'm struggling with how to go about implementing it. Here's my attempt:
const swapElements = (array, x, y) =>
R.pipe(updateArray(y, array[x], updateArray(x, array[y])))
The issue here lies in the fact that the curried version of updateArray (after receiving two arguments) expects an array input, while I am passing 3 arguments to the swapElements function.
Is there a way to use pipe when the main function receives different arguments compared to the initial function within the pipe?
Thank you.