First-class functions can be assigned to variables, passed to other functions as arguments, or returned from other functions. The ability to return a function enables deferred execution. Functions that accept other functions as arguments are called higher-order functions.
Questions tagged [first-class-functions]
132 questions
3
votes
0 answers
How to pass differently-typed composable functions up front in type-safe way?
I have a ValuePropagator:
V = TypeVar("V")
class ValuePropagator(ABC, Generic[V]):
@abstractmethod
def get(self, funcs: Sequence[Callable[[V], V]], value: V) -> V:
pass
A sample implementation propagates value eagerly, calling all…

Mario Ishac
- 5,060
- 3
- 21
- 52
3
votes
2 answers
PHP supports first-class functions, what does it mean
What does this statement mean in php,
PHP supports first-class functions
Would anyone explain briefly, I seems not to understand while reading the documentation.
I would appreciate an example.

muya.dev
- 966
- 1
- 13
- 34
3
votes
2 answers
What makes Python not a functional programming language?
Python variables are duck typed, mutable and it's functions can be written to have side effects. (In other words, it has a lot of non-functional programming features.)
However, it also has first-class functions and yet it's not a functional…

franklin
- 1,800
- 7
- 32
- 59
3
votes
2 answers
The vocabulary of first class functions
When people say that Python, for instance, has first class functions, it makes it sound like Python also has second class functions. However, I've never yet (knowingly) encountered a second class function in Python. When we say this, does it really…

Addem
- 3,635
- 3
- 35
- 58
3
votes
3 answers
How can I pass a function to a templated function A which may have a different signature based on another parameter to A?
I would like to create a template using a type, as well as passing a function which has a template argument which contains that type.
Here is what I currently have:
#include
void fooRef(int& ref) { std::cout << "In ref" << std::endl;…

Andrew
- 1,355
- 2
- 13
- 28
3
votes
3 answers
How to put method in map?
I have Strings where I need to find brackets (), {}, [] and using stack to check correctness and if there is a mistake to print the position of mistake . So i split them into char array and then want to check symbol by symbol and if its match my map…

Eugene Shymko
- 173
- 2
- 11
3
votes
1 answer
Pari/GP: the user defined function as a return value
I have a problem with Pari/GP user defined functions making use of user defined functions returning functions. Here is a dumbed-down example:
? f(x) = { (t) -> x + t }
%1 = (x)->(t)->x+t
? g(x) = { local(y); y = f(x); (t) -> y(t) }
%2 =…

Alexander Klauer
- 957
- 11
- 18
3
votes
3 answers
Accessing a Class Member from a First-Class Function
I have a case class which takes a list of functions:
case class A(q:Double, r:Double, s:Double, l:List[(Double)=>Double])
I have over 20 functions defined. Some of these functions have their own parameters, and some of them also use the q, r, and…

dbyrne
- 59,111
- 13
- 86
- 103
3
votes
3 answers
Assigning document.getElementById to another function
I am trying to do the following in JavaScript:
var gete = document.getElementById;
But I am getting the following error (From FireBug's Console):
uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object" nsresult:…

Andreas Grech
- 105,982
- 98
- 297
- 360
3
votes
2 answers
I've added a function to a Scala list, now how do I remove it?
Given the following Scala code:
val buffer = new scala.collection.mutable.ArrayBuffer[Function0[Boolean]]
def foo(): Boolean = { println("foo"); false }
def bar(): Boolean = { println("bar"); true }
buffer += foo
buffer += bar
I've added two…

Arthur Shagall
- 33
- 3
3
votes
3 answers
Breaking in functions passed to LINQ-functions
I have a function that is passed to Select. But when I put a breakpoint in said function the program does not break.
Example:
public static int PlusTwo(int x)
{
return x + 2;
}
public static void Main(string[] args)
{
var foo = new[] { 2, 3, 5,…

Philippe
- 1,715
- 4
- 25
- 49
3
votes
2 answers
When invoking a closure in JavaScript, is a new execution context created when entering the closure code?
Notice the closure example below: