I am starting with functional programming / fp-ts
.
I am trying to write a function that, taking a list, retains an element if a condition on the next element is fulfilled.
Example:
const condition = (i: number) => i % 10 === 0;
filterNext(condition, [19, 20, 3, 18, 8, 48, 20, 4, 10]) // => [3, 4]
I may also need to extend this so that both the match and the next element are included, as:
const condition = (i: number) => i % 10 === 0;
filterNext(condition, [19, 20, 3, 18, 8, 48, 90, 4, 10]) // => [10, 3, 90, 4, 10]
I have no idea how to build a proper pure function to do so for either of the two.
Any hints would be welcome.