Questions tagged [first-class-functions]

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.

132 questions
0
votes
1 answer

How these two functions are equivalent?

I am reading a book Mostly adequate guide and in the chapter about First Class functions, I have come across this example. Can somebody explain it to me? It says the below two lines are equal. // ignorant const getServerStuff = callback =>…
Nida Munir
  • 461
  • 3
  • 23
0
votes
2 answers

Haskell - fast naming of projection functions

Suppose I want to define a function f in terms of some other predefined function g as follows: f :: Int -> Int -> Int f 2 b = g b f _ _ = 1 That is, I want to define the projection, f(2,_) : Int->Int to be the same as g(_) : Int->Int. Gladly,…
0
votes
1 answer

"Using generic type 'Func' requires 1 type arguments" issue when defining a delegate function type with more than 4 arguments

I receiving the following error: "Using generic type 'Func' requires 1 type arguments". It occurs when I attempt to define a dictionary which maps strings to delegate functions. The dictionary looks like this: Dictionary
Oliver Hare
  • 29
  • 1
  • 7
0
votes
0 answers

Replacing Element in a Set if a condition is met

I'm working with a Set of CarCagetory: public struct Images { static let categoryTeaser = UIImage() } public enum PremiumModel { case model1, model2, model3, unknown } public struct CarCategory { public let teaserImage: UIImage …
gmoraleda
  • 1,731
  • 1
  • 17
  • 44
0
votes
2 answers

Perform math operations inside Python switch case equivalent

I am trying to simplify an if-elif-else block in Python with a Switch case equivalent. But I am having issues trying to perform math operations inside the switch case dictionary I am performing this code inside a FOR loop that is running through a…
0
votes
1 answer

Difference between these python visitor design pattern implementation choices?

I was reading the implementing_the_visitor_pattern_without_recursion from Python Cookbook, Third Edition The implementation with additional Visit Class fix the defect in the one without it as it claims. “One potential danger of this recipe…
0
votes
1 answer

Difference between a closure and the funarg problen?

I have a miss understanding, is the strainer function an example the downward funarg problem? I was using the chrome debugger under the sources panel and noticed this under the scope section. Is the strainer function param cb a closure or is the…
0
votes
1 answer

Python repeat function that calls functions

I have a program where the user should be able to pick and choose commands from a drop down list. In this list, there is also a repeat command, which does basically what a for loop does, so all the commands in between repeat and end repeat should be…
enrm
  • 645
  • 1
  • 8
  • 22
0
votes
3 answers

What are the differences between these two functions one uses first class? (javascript)

There are two functions one uses first class and assigning a function to a variable then returns the variable and the other one is just a regular simple function. In there, I don't get why is one better than the other one because they both looks…
Tsuna
  • 2,098
  • 6
  • 24
  • 46
0
votes
1 answer

Odd linked list/anonymous class behavior - executing when added?

This question is related to How to Queue and Call Actual Methods... Anyway, I've decided to (after all) go with the anonymous class idea. The problem is that when I ADD my anonymous class to the linked list, it's actually calling execute()…
0
votes
3 answers

How to comprehend the "first-class function" in swift?

I am reading some books about the functional programming in swift. When I see some books said the function in swift is "first-class function" and I confused what is the meaning of the "first-class". Can anybody answer me or give me some example…
Perry Chen
  • 50
  • 4
0
votes
1 answer

Not Understanding usage of First-class function and csv module events in node.js example

I'm having some trouble understanding the code in this code snippet. I've been commenting and researching, but I've run into a snag. Well I've run into two snags, but one has to do with an outdated csv library. Here is the code snippet: var…
Dimi
  • 187
  • 1
  • 2
  • 7
0
votes
1 answer

How to handle async functions in nodejs

I have been learning nodejs, and one thing that continues to boggle my mind is async programming that nodejs is built on. Maybe I am doing something wrong, but despite all my research I can't wrap my mind around how I should adapt to it coming from…
Nimbrod
  • 57
  • 11
0
votes
1 answer

Schema modelling with functions

I am looking for a schema language that allows definition of functions. I thought of http://json-schema.org/ at first, but that format is data-only. My knowledge from XSD is the same. The language is at first not important, my project is just…
0
votes
1 answer

convert method on type to function of type

Is it possible to convert a method on type T to a function of type T? For example, if I have case class T { def foo(u : U) : Unit = ??? } make it possible to pass foo as the argument somef in some way to function bar(somef : (T, U) => Unit) So…
Martijn
  • 11,964
  • 12
  • 50
  • 96
1 2 3
8
9