1,620 questions
-1
votes
2
answers
101
views
Change behavior of function depending on type [closed]
I have a function where one of the variables is either a function x(t) or sometimes, for convenience, I'll be using x_t:=x(t)
The following is pretty emblematic of what I'm up to:
def foo(t,y,x):
...
-4
votes
3
answers
151
views
lambda functions as higher-order functions [closed]
I'm learning about higher-order functions, specifically lambda functions in Python. I understand lambda functions to an extent, but a little confused about this lambda higher-order function example.
...
0
votes
1
answer
75
views
NextJs Api export route using High Order Functions is not working
The NextJS app has two HOFs that each inject data into a function param. The resulting function is exported as an Api route. It has the error:
Server Actions must be async functions.
Here is the ...
0
votes
2
answers
250
views
Why does `foldl'` have the implicit reversal?
Recently to better understand the advantages and disadvantages of lazy evaluation, I check for some details of Haskell. I did that to do exercise 5.9 in SDF (Software Design for Flexibility)
More ...
2
votes
0
answers
97
views
Function parameter that is generic over mutabiliy of its argument, e.g. Fn(&T) / Fn(&mut T)
Let's say we have a function that applies a parameter to its input function
fn apply_fn<'a, F>(f: F)
where
F: Fn(&mut u32),
{
let mut i = 1;
f(&mut i);
}
This works as ...
0
votes
4
answers
453
views
Swift array `filter`, `map`, etc. (higher-order functions) when the closure needs to be `async`
Now that I'm living completely in a Swift 6 async/await world, I've suddenly hit a snag. When writing code of this sort (never mind what it does, just look at the form of the thing):
let result = ...
0
votes
1
answer
80
views
Passing a constructer as a parameter as if it were a regular function in JavaScript?
I am using ANTLR 4, and it is common to instantiate a class and immediately pass it as the argument of the next class' constructor, as per the docs for the ANTLR 4 JavaScript target:
import antlr4 ...
0
votes
1
answer
43
views
Application not a procedure when calling higher order function
I am writing a program that will playback a list of frames as a movie. But before it play it back I want to apply a modifier procedure to every frame in the list. for some reason when calling the ...
1
vote
1
answer
97
views
How to correctly type a transduce function in TypeScript?
Below is a minimal transduce implementation, but its output type is incorrect. Looking for what needs to change to correct it. Here's the example in a TS Playground containing transduce and all ...
1
vote
1
answer
38
views
How get a wrapped function to return the correct type?
How to get this reduce function to return type Set<1>? (Playground)
const toSet = <const V>(acc=new Set<V>(),v:V) =>{
acc.add(v);
return acc;
}
const set = toSet(undefined,1); ...
1
vote
1
answer
207
views
Rust higher order method?
If I wanted to generate a polynomial function in Rust, one way to do it is the following,
fn new_polynomial(vec: Vec<i32>) -> impl Fn(i32) -> i32 {
move |x| vec.iter().fold(0, |acc, a| ...
0
votes
2
answers
123
views
Passing a variadic function to a variadic function via a pointer
I'm kinda confused with the usage of <stdarg.h> features. I can't figure out how to properly pass a va_list to the argument function. Here's a simplified example of what I'm trying to achive:
#...
1
vote
2
answers
348
views
Type inference not working for higher-order functions in TypeScript
TypeScript does not infer properly the generic type of a function that accepts a function that exposes as its argument a function that when called should be provided with an argument that is generic.
...
3
votes
0
answers
38
views
Curry Predicate [duplicate]
Is there a workaround in typescript to have a predicate on a higher-order function?
type One = {
_type: 'one';
value: unknown;
};
type Two = {
_type: 'two';
value: unknown;
};
type ...
8
votes
1
answer
400
views
Why is a function that only returns a stateful lambda compiled down to any assembly at all?
The following non-templated (or is it?) function returning a non-generic, stateful lambda,
auto foo(double a) {
return [a](double b) -> double {
return a + b;
};
}
compiled down to ...