6

I am playing around with this beautiful language and saw a function called noop.

As the documentation says it's a void function that does nothing!!

So why would I use a function that does nothing? Is it for adding "Nop" in assembly (for pipeline etc) but then this would be too low-level wouldn't it?

Lii
  • 11,553
  • 8
  • 64
  • 88
niceman
  • 2,653
  • 29
  • 57

2 Answers2

8

noop() can take the place of any void (or Anything returning) function. So it's useful to use as a value if you are calling a function or creating an object that requires you to pass in an event handler or callback function, but you aren't interested in responding to the event.

John Vasileff
  • 5,292
  • 2
  • 22
  • 16
7

noop() is also useful as the default value of an an optional parameter of a function, for example:

void foo(void bar(Integer i) => noop(i)) {}

Or:

void foo(Anything(Integer) bar = noop) {}
Gavin King
  • 3,182
  • 1
  • 13
  • 11