{
  "id": "enwiki-001373121774",
  "slug": "callable-object",
  "title": "Callable object",
  "qid": "",
  "lead": "A callable object, in computer programming, is any object that can be called like a function.",
  "body": "A callable object, in computer programming, is any object that can be called like a function. import std; struct Foo { void operator()() const { std::println(\"Called.\"); } }; int main() { Foo instance; instance(); // This will output \"Called.\" to the screen. } $a = array(3, 1, 4); usort($a, function ($x, $y) { return $x - $y; }); It is also possible in PHP 5.3+ to make objects invokable by adding a magic __invoke() method to their class: class Minus { public function __invoke($x, $y) { return $x - $y; } } $a = array(3, 1, 4); usort($a, new Minus()); class Foo: def __call__(self) -> None: print(\"Called.\") class Bar: ... instance: Foo = Foo() instance() # Outputs \"Called.\" to the screen assert(callable(instance)) # True since instance has __call__ assert(callable(zip)) # True since zip is a function, despite not having __call__ assert(callable(Bar)) # True since Bar is a class, despite not having __call__ assert(callable(lambda x: x)) # True since lambdas have __call__ A collections.abc.Callable type annotation can be used to declare that a given variable must be callable. A Callable[P, R] , where P is a list of types and R is a type, can be called with values matching P as arguments and returns a value of type R . Other values for P , such as a ParamSpec or ... , denote more flexible cases. def spam(ham: int, eggs: str) -> None: return None func: Callable[[int, str], None] = spam none: None = func(0, \"foo\") Callable objects are defined in Dart using the call() method. class WannabeFunction { call(String a, String b, String c) => '$a $b $c!'; } main() { var wf = new WannabeFunction(); var out = wf(\"Hi\",\"there,\",\"gang\"); print('$out'); } struct CallableStruct { var value: Int func callAsFunction(_ number: Int, scale: Int) { print(scale * (number + value)) } } let callable = CallableStruct(value: 100) callable(4, scale: 2) callable.callAsFunction(4, scale: 2) // Both function calls print 208. ==References==",
  "categories": [
    "10637301",
    "109372261",
    "20589555",
    "22926615",
    "23468805",
    "24043274",
    "25257581",
    "27395026",
    "39691156",
    "43573932",
    "57958211",
    "62213919"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1373121774",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1788489023.0,
  "claims": [],
  "contradictions": [],
  "confidence": 0.6,
  "csl": {
    "id": "enwiki-001373121774",
    "type": "webpage",
    "title": "Callable object",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/callable-object",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          19
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          19
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001373121774",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1373121774",
    "note": "Immutable snapshot enwiki-001373121774"
  }
}