Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R.noop #701

Closed
mondalaci opened this issue Dec 23, 2014 · 20 comments
Closed

R.noop #701

mondalaci opened this issue Dec 23, 2014 · 20 comments

Comments

@mondalaci
Copy link
Contributor

It'd be useful to have a function that doesn't do anything.

R.noop = function() {}; // obviously, noop stands for no operation

Could be used in scenarios like:

(functionArray[selectedItem] || R.noop)();
@raine
Copy link
Member

raine commented Dec 23, 2014

noop was recently discussed in #596

@buzzdecafe
Copy link
Member

R.always()

@mondalaci
Copy link
Contributor Author

@buzzdecafe How did you mean in #596 that noop feels pretty side-effect-y to you? R.always() definitely works in this case but the name is very confusing for the reader. noop suggests the purpose of the code much better in such cases.

@buzzdecafe
Copy link
Member

IMO R.always() is abuse, but it solves this problem. I think noop feels side-effect-y because it does not do anything with any input value, and doesn't return any values either. So what is it for?

@mondalaci
Copy link
Contributor Author

@buzzdecafe It doesn't do anything, hence its name. :) I understand your argument but I still think that a function that doesn't do anything has its place in a functional library like Ramda. A good example scenario is the one I provided on the top of this thread. Even some non-functional libraries like Angular include it - https://docs.angularjs.org/api/ng/function/angular.noop

@buzzdecafe
Copy link
Member

I certainly see the utility of noop, I just don't see how it belongs here. IMO ramda should be about evaluating expressions, as opposed to performing operations.

@mondalaci
Copy link
Contributor Author

Well, I guess I'm out of arguments. For me this comes down to practicality but your reasoning is certainly more nuanced. I can continue to use angular.noop, although R.noop would make more sense and be shorter.

@buzzdecafe
Copy link
Member

anyone else have $0.02? @CrossEye ? @davidchambers ? Bueller?

@davidchambers
Copy link
Member

I added _.noop to Underscore; I see the value. I agree with @buzzdecafe, though, that it's not in the spirit of Ramda. I'm fine with function() {}: it's very clear. I don't feel strongly about this, so I'll neither promote nor oppose the addition of R.noop.

@CrossEye
Copy link
Member

What are its arguments? What does it return? Is it idempotent? Does it mutate input objects?

😄

I also don't feel strongly.

It feels very strange to have a function with no return value inside Ramda. And anyone who wants this can add it easily. We haven't tried to do anything like the extension mechanism that Lo-Dash uses, but it would be trivial for anyone to use Ramda's exposed object as a namespace, I suppose, to add such things as this if they wanted:

R.noop = R.always();

But there are clearly times when it's useful.

I probably would not reject a PR (although perhaps @buzzdecafe would.) But I wouldn't be excited by one.

@buzzdecafe
Copy link
Member

if no one wants to fight for it, i'm gonna close it

@despairblue
Copy link

I'd like that function since it makes the use case below was easier:

var noop = () => undefined

R.cond(
  [R.eq('Known Error 1'), noop],
  [R.eq('Known Error 2'), noop],
  // something we don't expect and thus want to log
  [R.T, error => error]
)('Known Error 1')

// instead of  

R.cond(
  [R.not(
    R.anyPass([
      R.eq('Known Error 1'),
      R.eq('Known Error 2')
    ])
  ), error => error]
)('Known Error 1')

the noop function would ignore all arguments, return undefined and have no side effects, basically be function(){} or () => undefined

@CrossEye
Copy link
Member

There are three questions:

  • is the function useful?
  • does it fit well with Ramda?
  • is it easy to work around not having it?

Clearly it's useful. I use some version of it often.

But I don't think it fits well with Ramda. Ramda is about dealing with values. This would be very much an oddball function in Ramda.

And it's very easy to create, either manually, as you've done in your example, or with Ramda:

var noop = R.always(undefined);

If you want to use ramda's R as a namespace for your own functions, you could do this:

R.noop = R.always(undefined);

I don't have a serious objection to this; it simply doesn't feel like a good fit.

@mondalaci
Copy link
Contributor Author

I don't think that the "it's easy to create" argument is a valid one. I personally rather don't want to extend libraries in any ways because later on a developer can come along looking up the library reference and (s)he won't find the function that I added, leading to confusion.

@buzzdecafe
Copy link
Member

I don't think that the "it's easy to create" argument is a valid one

I don't think that is especially persuasive either. IMO the best arguments are:

  1. as above: "IMO ramda should be about evaluating expressions, as opposed to performing operations." (argumentum ab auctoritae maea?)
  2. noop is just sugar for always(undefined)

@CrossEye
Copy link
Member

I absolutely agree that "ramda should be about evaluating expressions, as opposed to performing operations." (So it's at least argumentum ab auctoritate nostra.)

@despairblue
Copy link

Ok, convinced :)

@microcipcip
Copy link

@despairblue and anybody getting to this thread...noop is available in Ramda Adjunct

@tommmyy
Copy link
Contributor

tommmyy commented May 9, 2018

... and Ramda-extension for really long time

@microcipcip
Copy link

@tommmyy OMG I had no idea about this project, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants