Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [higher-order-functions]

Higher-order functions are functions which either take functions as arguments or return them as output (or both). They are a cornerstone of functional programming.

Filter by
Sorted by
Tagged with
2 votes
4 answers
524 views

What would be a good analogy for explaining higher order functions?

I am teaching a beginners course on JavaScript programming and web development. Passing a function as a value into another function is a very common thing in JS from the very beginning. As the ...
lishaak's user avatar
  • 467
-1 votes
1 answer
173 views

How should I document a higher-order Python function?

I'm interested in designing a high level function in Python, (I.E. a function that takes other functions as arguments) but I don't know of any good conventions for documenting such a function. For ...
Visipi's user avatar
  • 9
10 votes
5 answers
7k views

How to name a function that returns a function?

Let's say, for example, that I have a function makeFoo that makes another function foo: function makeFoo(string) { return () => string } const foo = makeFoo('bar'); I know that makeFoo is a ...
Splox's user avatar
  • 209
0 votes
3 answers
517 views

Do higher order functions violate the separation of data and code principle?

I am asking here something that is really haunting for years (for real !). I guess in a "perfect world", we would have programs made of data models and functions, and those functions manipulate data ...
ibi0tux's user avatar
  • 241
3 votes
3 answers
583 views

Language design : How to type higher order functions parameters?

I'm trying to design a theoretical programming language and I'm facing a problem with high order functions. The language is strong-typed, so the way to define a standard function is like so : ...
ibi0tux's user avatar
  • 241
1 vote
1 answer
166 views

JS Higher Order Function is even necessary in this scenario?

In Javascript, I have seen a code like: const getSomeMapper = (param1, param2, param3) (param4, param5, param6) => { // uses all these params and returns a promise } interface ...
Craftein's user avatar
  • 113
0 votes
2 answers
1k views

Does chaining higher order functions mean worse performance?

For clarification, let's review the following example: Consider that we have the following array of Ints: let array = [1, 2, 3, 4, 5] and we've been asked to generate a new array from array ...
Ahmad F's user avatar
  • 101
3 votes
2 answers
825 views

What differentiates function objects from poltergeists?

The Short (Original) Version How are function objects, sometimes called "functors" in C++ and other OO languages, where they make sense different from classes symptomatic of the poltergeist anti-...
Greg Kramida's user avatar
1 vote
2 answers
866 views

High order functions: What's the benefit returning a function compared to a value?

In order words, what's the advantage of writing this: Listing 1 var sortBy = function sortBy(p) { return function (a, b) { return a[p] > b[p]; }; }; Compared to this? Listing 2 var ...
alex's user avatar
  • 383
7 votes
2 answers
230 views

Are lower-arity functions subtypes of higher-arity ones?

I've found that there isn't a concept similar to "arity-based subtyping" in many languages that I've programmed in, where higher-order functions could consume functions of lower arity than their ...
concat's user avatar
  • 517
3 votes
1 answer
263 views

State propagation(bottom-up) in multi-walk tree

Using the Tree representation(mentioned below), typedef enum {Running, Warning, Critical}Status; struct TreeNode; typedef struct List{ int childCount; struct treeNode **childList; }List; ...
overexchange's user avatar
  • 2,265
1 vote
2 answers
302 views

How to name a function that copy or rename a file/directory

I have a function function name(src, dest, remove) { copy(src, dest); if (remove) { delete(src); } } What name should I give to that function? Alternatively higher order function ...
jcubic's user avatar
  • 143
1 vote
1 answer
105 views

How to preserve parameter names when using bind to define new methods

I'm writing javascript object that wraps REST requests. For every operation on the server there is a method that accepts the parameters for the request and a callback that will receive the results. (...
Kasper van den Berg's user avatar
2 votes
6 answers
806 views

Function creating function, compiled languages equivalent

I'm new to compiled languages. I'm learning C. I'm used to coding in python. I was wondering if there was any equivalent, or replacement method in compiled langues for functions able to create a ...
loxaxs's user avatar
  • 147
4 votes
1 answer
1k views

How to move from OOP object composition to FP function composition in C#

I have been working for a few weeks on a new web project and I am realizing that all I am doing is basically calculations and transformations on data, and that most of my classes do not contain any ...
Carlos Rodriguez's user avatar
1 vote
4 answers
14k views

How does this function returning a function work?

I'm having a hard time understanding exactly what is happening in the code here and how this script is changing other functions. This is taken from eloquentjavascript.net chapter 5 on higher order ...
user213229's user avatar
2 votes
1 answer
852 views

Why use tuples as function parameters in languages that support currying?

In languages that support currying, I can't think of many cases where using a tuple as function input parameters would be better than breaking the tuple apart into multiple parameters, which then ...
xji's user avatar
  • 781
1 vote
3 answers
136 views

Using higher order functions to apply m out of M filter's and then transform data of size n?

Total no: of filters possible is M . User can select m filters where m <= M . A typical example is files from a folder , he could say modified between so and so date , start with so and so and so ...
Nishant's user avatar
  • 575
0 votes
2 answers
227 views

higher order functions equivalent construct in TIOBE top 10 languages [closed]

I'm trying to find a language construct equivalent to higher order functions in the top 10 languages from TIOBE index. Here are my results so far: C - function pointers Java - anonymous methods, ...
Grzegorz Sławecki's user avatar
0 votes
0 answers
112 views

Why use subtyped functions?

Say you have arguments A1 >: A2 (contra-variant), and return types B1 <: B2 (covariant). The corresponding functions are such that: A1 => B1 <: A2 => B2 Sometimes, this makes sense to me - ...
tunesmith's user avatar
  • 121
2 votes
1 answer
883 views

How to simplify unit testing with higher order functions?

this is not a question on how to write unit tests this is not a question on what to test this is a question on reducing the typing needed overall for a personal testing framework I know you can send ...
user2738698's user avatar
20 votes
1 answer
14k views

Passing a Scala function to a Java 8 method

The following Scala code works and can be passed to a Java method expecting a function. Is there a cleaner way to do this? Here's my first pass: val plusOne = new java.util.function.Function[Int,...
GlenPeterson's user avatar
  • 14.9k
26 votes
3 answers
9k views

Naming convention for higher order functions? [closed]

Is there a naming convention for higher order functions? That is, functions which return other functions. An example in Javascript: function onlyDivisibleBy(div) { // <-- higher order function ...
nickf's user avatar
  • 637
11 votes
1 answer
1k views

Origin of common list-processing function names

Some higher-order functions for operating on lists or arrays have been repeatedly adopted or reinvented. The functions map, fold[l|r], and filter are found together in several programming ...
Heatsink's user avatar
  • 306
9 votes
2 answers
1k views

Who first coined the term Higher Order Function and/or First Class Citizen?

I've come to understand that long before Haskell, O'Caml or LISP, higher order functions were an academic research subject and in mathematics, Schönfinkel (in 1967) and Haskell Curry (in 1968) already ...
Abel's user avatar
  • 922
5 votes
2 answers
520 views

Determinism of functions using PRNG in Clojure and functional languages

I'm a bit surprised by a sentence found in the book "Clojure Programming" (1st [and only as I write this!?] edition), page 78: It should be obvious that it's impossible to deterministically test a ...
Cedric Martin's user avatar
9 votes
4 answers
3k views

What's special about currying or partial application?

I've been reading articles on Functional programming everyday and been trying to apply some practices as much as possible. But I don't understand what is unique in currying or partial application. ...
Vigneshwaran's user avatar
6 votes
3 answers
1k views

Functional Methods on Collections

I'm learning Scala and am a little bewildered by all the methods (higher-order functions) available on the collections. Which ones produce more results than the original collection, which ones ...
GlenPeterson's user avatar
  • 14.9k