-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
  • 17,580
  • 5
  • 58
  • 84
Joe
  • 4,274
  • 32
  • 95
  • 175

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
  • 9,420
  • 2
  • 23
  • 40