0

I'll start with the question itself.

Can someone give me a word or words as a method name that would be a forward-direction if-statement?

My explanation of the question will begin with an analogy.

'add' is to 'plus' as 'if' is to what?

It may be better expressed as:

add 10 to 5         => 5 + 10
if true then action => action (?) true [OR] true (?) action

The reason for the [OR] above is because of the direction of intent:

add 10 to 5         => 5 + 10
     |----^            ^---|

if true then action => action (?) true [OR] true (?) action
    ^----------|         |---------^         ^---------|

I don't know what makes the most sense in terms of direction. The reason I'm relating this to functional programming is that I want to make an extension method in C# where it looks like:

bool.[FuncName](action)

Within the language, I think it is easier to read left-to-right as in the '5 + 10' example above. So, my method would extend boolean and require the action as a C# Action. I'm looking for the correct name to name this method.

If you want the other direction, it would look like this:

action.[FuncName](bool)

And in code (if I wrote the extension method this way):

(new Action(TestMethod)).If(testBool);

But that is backwards of how you'd think about it naturally. It is saying, "If testBool on the right is true, then execute the action TestMethod on the left." The word 'If' makes sense because, in general, it is saying "This action occurs if this condition is true." But, I want the word or words to be a forward-direction version of an if-statement.

The closest I've thought of:

testBool.WhenTrue(new Action(TestMethod));

What do you guys think?

Michael Yanni
  • 1,476
  • 4
  • 17
  • 29

0 Answers0