-3

I want a function that returns a value when a function returns a value which is not null.

const getSomeValue = R.filter(...);

const getSomeOtherValue = R.propEq('name');

The R.until function is probably the one to use.

Some pseudo code:

R.until(R.isNotNull, R...[getSomeValue, getSomeOtherValue]);

So run through the functions until the returned value is not null.

I don't find any suitable function in the Ramda docs to do this.

Any ideas?

customcommander
  • 14,568
  • 4
  • 48
  • 68
Joe
  • 5,210
  • 27
  • 83
  • 156

1 Answers1

0

If you don't mind to also ignore falsy values (false, undefined, 0, etc...) then you could use R.either:

const first = () => {
  console.log("first");
  return null;
};
const second = () => {
  console.log("second");
  return {a: "banana"};
};
const third = () => {
  console.log("third");
  return {a: "chicken"};
};

const fn = R.either(first, second, third);
console.log(fn());
<script src="https://unpkg.com/ramda@0.26.1/dist/ramda.min.js"></script>
Turtlefight
  • 7,034
  • 1
  • 18
  • 37