Check value in when inside an pipe function

ridermansb

if R.cond resolve an not undefined value, should execute a pipe function and pass the value to the pipe function...

const publishClient = (resp, cb) => {
  console.log('Publishing ', resp);
  cb()
}

// Applying same process
const format = (letter) => ({'letter': letter});
const concact =  R.curry((num, letter) => num + '=' + letter);

// my method publish
const publish = partialRight(publishClient, [function() { console.log('Callback called!') }]);

// conditions to check
const condToRes = R.cond([
  [equals(1), concact('A')],
  [equals(2), concact('B')],
  [equals(3), concact('C')],
  [equals(4), concact('D')],
  [equals(5), concact('E')],
]);

// Publish only if condition resolves
// const resolveCond = when(condToRes, pipe(format, publish)) // NOT WORK,concact FN is ignored!
const resolveCond = pipe( // TRYING
  condToRes,
  when(HOW TO CHECK condToRes IS NOT NIL, pipe(format, publish))
);


// Call
resolveCond(1)

// SHOULD DISPLAY ..
Publishing 
{"letter":"A=1"}
Callback called!
Scott Christopher

To test whether a value is null or undefined you can make use of R.isNil. When combined with the R.complement combinator, this will produce a function that evaluates to true when applied to a value that is not null/undefined.

This can be used to update your example to:

const resolveCond = pipe(
  condToRes,
  when(complement(isNil), pipe(format, publish))
);

Alternatively, R.unless can be used instead of R.when, which removes the need to wrap R.isNil with R.complement.

const resolveCond = pipe(
  condToRes,
  unless(isNil, pipe(format, publish))
);

Both approaches are equivalent, though R.unless perhaps reads a little better.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

pass arguments when pipe is called inside a function

From Dev

Returning value from a function when the function itself called inside PYTHON

From Dev

Check value inside Map

From Dev

'Broken Pipe' error when reusing the same pipe inside a loop

From Dev

When function triggers, inside for loop number return default value again

From Dev

Value to a function inside a setTimeout

From Dev

Check if partial value is inside array

From Dev

check value inside a link javascript

From Dev

Check if function is inside a recursive function call

From Dev

How do I check for a specific letter inside a value in a dictionary when there are other letters/numbers in it?

From Dev

How do I check for a specific letter inside a value in a dictionary when there are other letters/numbers in it?

From Dev

node js - how do I return a value from a function when it depends on asynchronous function inside

From Dev

How to Manipulate Variable Value inside a Function When The Variable was Declared Outside the Function?

From Dev

Angular 2 Pipe - can't return value inside a promise

From Dev

Unable to get the accurate value of shell variable set inside a pipe

From Dev

Angular 2 Pipe - can't return value inside a promise

From Dev

passing the function parameter value to the function inside that function

From Dev

How can I check if my function is called with input from a pipe?

From Dev

How to check for a value in array of strings with ngIf using async pipe?

From Dev

Angular 2 : Search pipe not working when input inside a form tag

From Dev

how to get a value inside a function

From Dev

How to change value inside function

From Dev

Change the value of a variable inside a function

From Dev

Add a value to an object inside a function

From Dev

Rcpp function check if missing value

From Dev

Check if value in array (include is not a function)

From Dev

Check if value in array (include is not a function)

From Dev

Implement counter inside function to check progress

From Dev

How to check button is clicked inside a function

Related Related

  1. 1

    pass arguments when pipe is called inside a function

  2. 2

    Returning value from a function when the function itself called inside PYTHON

  3. 3

    Check value inside Map

  4. 4

    'Broken Pipe' error when reusing the same pipe inside a loop

  5. 5

    When function triggers, inside for loop number return default value again

  6. 6

    Value to a function inside a setTimeout

  7. 7

    Check if partial value is inside array

  8. 8

    check value inside a link javascript

  9. 9

    Check if function is inside a recursive function call

  10. 10

    How do I check for a specific letter inside a value in a dictionary when there are other letters/numbers in it?

  11. 11

    How do I check for a specific letter inside a value in a dictionary when there are other letters/numbers in it?

  12. 12

    node js - how do I return a value from a function when it depends on asynchronous function inside

  13. 13

    How to Manipulate Variable Value inside a Function When The Variable was Declared Outside the Function?

  14. 14

    Angular 2 Pipe - can't return value inside a promise

  15. 15

    Unable to get the accurate value of shell variable set inside a pipe

  16. 16

    Angular 2 Pipe - can't return value inside a promise

  17. 17

    passing the function parameter value to the function inside that function

  18. 18

    How can I check if my function is called with input from a pipe?

  19. 19

    How to check for a value in array of strings with ngIf using async pipe?

  20. 20

    Angular 2 : Search pipe not working when input inside a form tag

  21. 21

    how to get a value inside a function

  22. 22

    How to change value inside function

  23. 23

    Change the value of a variable inside a function

  24. 24

    Add a value to an object inside a function

  25. 25

    Rcpp function check if missing value

  26. 26

    Check if value in array (include is not a function)

  27. 27

    Check if value in array (include is not a function)

  28. 28

    Implement counter inside function to check progress

  29. 29

    How to check button is clicked inside a function

HotTag

Archive