Questions tagged [anonymous-function]

Anonymous functions use a block of code as a value, defining it as an inline function without a name.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
33 views

When exactly is the deferred statement is executed [duplicate]

Here's golang program: package main import "fmt" func example() (result int) { defer func() { result = result * 2 }() fmt.Println("Executing main logic") return 42 } func ...
vishalvivekm's user avatar
1 vote
2 answers
82 views

Elegant solution to the "Lambdas" vs "Generics" problem?

I am looking for a prettier solution here. The problem is to combine Generics and Lambda Expressions. According to the Java Language Specification this it not possible the way I want. So my question ...
JayC667's user avatar
  • 2,504
2 votes
1 answer
79 views

How to read name of anonymous lambdas in Visual Studio call stack?

It's always been challenging to me to track anonymous lambdas in the call stack, so I wrote some sandbox code in order to deal with the issue: int main() { [] { std::cout << "Hello ...
Kaiyakha's user avatar
  • 1,525
3 votes
1 answer
53 views

How are closures actually sent for evaluation in lambda expression calls

I'm trying to understand how closures are actually sent for lambda expressions calls: #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int *A = (int *) malloc((...
OrenIshShalom's user avatar
2 votes
1 answer
53 views

In Julia, what is the type of an anonymous function when an outer scope is involved?

I can create an anonymous function within a list comprehension in Julia. I expect that this would create a type of Vector{Function}. Instead, the type is something like Vector{var"#2#4"}. ...
user292301's user avatar
0 votes
1 answer
96 views

How to override anonymous function in JavaScript with Tampermonkey?

I have a function I want to override in an anonymous function with Tampermonkey. (()=>{ /* other stuff */ function Zm(e) { let {visible: t, onCancel: n} = e; const ...
ZeroPhase's user avatar
  • 649
1 vote
0 answers
35 views

PHP: Write anonymous function to file for later use

Let's assume, we have an array with anonymous functions as values. It has following contents: $fpool = [ 'f1' => function($a){ if($a > 0){ return [$a*$a, $a+$a]; }...
user2624744's user avatar
0 votes
1 answer
85 views

function gives "2nd argument: not valid character data" error

I am new to elixir and I am trying to make a recursive anonymous function, but for some reason my anynymous function that works on it's own as expected throws me "2nd argument: not valid ...
Djordje Vuckovic's user avatar
0 votes
0 answers
29 views

I can't set the "onclick" attribute of an element in JS

I'm working in vanilla JS. Here is my function as of now function displayQueue() { queueDiv.innerHTML = ""; for (var i = 0; i < queue.length; i++) { let newDiv = document....
Uperscuzzi's user avatar
0 votes
0 answers
41 views

MATLAB optimization function variable assignment in anonymous function

I have an optimization problem in MATLAB and I'd like to be able to write an anonymous function to pass to the optimization function. The function I am minimizing is a function of x, but I am required ...
pheon's user avatar
  • 2,897
0 votes
1 answer
47 views

Is anonymous function expression?

Is an anonymous function expression? if it is, why can not we use it wherever JavaScript expects an expression? Example : const result = String(function () { return 2; }); what variable returns :...
radman's user avatar
  • 21
0 votes
0 answers
59 views

How to execute/override a JavaScript function declared in anonymous function

How can I execute a function that is defined in an anonymous function ? For example, I've this method "openProfile" declared in anonymous function. I would like to override it / call it ...
Сорок два's user avatar
0 votes
1 answer
37 views

delegate and cancellationtoken troubleshooting

I can't understand why I'm getting System.NullReferenceException: Object reference not set to an instance of an object. exception. I would like to pass the delegate ConnectAsyncDelegate to Commit ...
Alexey Alferov's user avatar
0 votes
1 answer
82 views

Is it safe to use the reference result of a function within an anonymous function which is used as the parameter in C#?

Is it safe to use the reference result of a function within an anonymous function which is used as the parameter? Following is a simplified example: ClassA result = null; result = instanceA....
ArtS's user avatar
  • 1,778
0 votes
2 answers
28 views

replacing elements of character vector with anonymous function does not return full vector

I'm confused by the following behaviour: y <- letters |> (\(x) x[stringr::str_which(x, "a|e")] <- c("1", "2"))() which returns [1] "1" "2" ...
deschen's user avatar
  • 10.2k
1 vote
1 answer
258 views

Binding variable in loop changes it's type

I'm trying to make some order in a script that uses nicegui. I'm using a dictionary to store all button labels and the pages they will redirect to. I'm iterating over all keys in pages dictionary and ...
redistor's user avatar
1 vote
0 answers
38 views

SciPy loadmat fails to load matlab structures with anonymous functions when simplify_cells=True

Scipy.io.loadmat fails to load matlab structures from .mat files when they contain anonymous functions if the simplify_cells switch is set to True. I believe the reason is because loadmat registers ...
Andrew Landau's user avatar
0 votes
1 answer
37 views

Typescript - Anonymous generic function

I've read quite a few things on the topic and got myself confused, if it turns out the answer is out there, I'll delete this question. Why would that not work: type SanitizeFunction = <T extends ...
Jonathan Adami's user avatar
1 vote
1 answer
242 views

Use on parenthesis () or use curly brackets {} in react component

I'm testing a react component, but have problems using an array map where is define an anonymous arrow function, and after arrow (=>) I use curly brackets. Then the inside code could not be ...
Dave's user avatar
  • 13
1 vote
1 answer
130 views

Per-iteration variable in Nim?

var functions: seq[proc(): int] = @[] functions.add(proc(): int = 233) for i in 1 .. 5: functions.add(proc(): int = i) for i in 1 .. 5: echo functions[i]() output 5 5 5 5 5 Seems like Nim ...
init 1's user avatar
  • 39
1 vote
1 answer
37 views

Accessing the first index of an anonymous function [duplicate]

If I have an anonymous function in MATLAB, say f = @(t) [t, t+5]; and I wanted to create a new anonymous function g that accesses the first index of f, so that, in this example, g = @(t) t; how can ...
ShonenMind's user avatar
0 votes
1 answer
52 views

Create an Anonymous Function with no Parameter in Scala

We know that in Scala reflection, we can invoke a method using clazz.getDeclaredMethod("method").invoke(instance, parameters) where the function signature of invoke is Object invoke(Object ...
Hang Wu's user avatar
  • 15
0 votes
2 answers
182 views

value nonEmpty is not a member of Object

Below code works fine on Scala 2.11 and getting error "value nonEmpty is not a member of Object" on Scala 2.12. Can someone provide a solution? val ds = spark.createDataset(List("abc&...
Surya's user avatar
  • 21
0 votes
0 answers
28 views

Why do I get an error when I try to use the format simplification of anonymous functions [duplicate]

In scala, if a parameter only appears once, can it be replaced by _, but why not here. i want to know why this way of coding is wrong,and what is the underlying principle? object ...
张子晗's user avatar
3 votes
1 answer
1k views

Generic function, can't be defined in form of anonymous?

e.g: func f[T any](t T) T { var result T return result } // this got error ! var fAnonymous = func[T any](t T) T { var result T return result } fAnonymous got error, it says: ...
Eric's user avatar
  • 22.8k
1 vote
1 answer
48 views

Types error when calling 2 functions inside a map

I'm quite new to Scala and trying to analyze some nice functional code for some exercises like below: object ArmstrongNumbers { def isArmstrongNumber(num: Int): Boolean = { val ...
Maciej Gajewski's user avatar
1 vote
1 answer
99 views

variable lifecycle in anonymous functions golang

im sorry if my question may has obvious or easy answer but i really cant undesrstand what is going on. this is my code: import "fmt" func main() { a := test() a() a() } func ...
aaryaa9978's user avatar
0 votes
1 answer
75 views

Python anonymous recursion without combinators

Is it possible to do some anonymous recursion in Python ? I mean, making a recursive lambda function, that does not call its name (so, it must work even if you don't assign the lambda). Also, I know ...
Oskar 79 115 99 97 114 80 108 's user avatar
1 vote
1 answer
143 views

Generated Julia function seems to always recompile

I wrote a function in Julia that generates a bunch of anonymous functions, something like this: function gen_funcs() funcs = [] for i = 1:1000 txt = "(a, b) -> some code" ...
Fernando's user avatar
  • 607
0 votes
2 answers
437 views

React - why do I need to wrap functions called by useState in an anonymous function?

I have been taking a React performance training course and this code base is used as an example: https://github.com/stevekinney/wordman/blob/main/src/components/application.jsx#L10 When we call the ...
user1261710's user avatar
  • 2,579
1 vote
1 answer
248 views

Determine the function signature of an anonymous function in scala

The context is to register a UserDefinedFunction(UDF) in spark, where the UDF is an anonymous function obtained via reflection. Since the function signature of the function is determined at runtime, I ...
Hang Wu's user avatar
  • 15
1 vote
1 answer
61 views

In React, why can't I pass a function reference to onClick?

I usually split my React applications by having a JSX component with only UI on one side, and a singleton class for business logic on the other side. The UI component code would look like this: ...
Fumée Noire's user avatar
1 vote
3 answers
253 views

Why onTap function runs without tapping when it have arguments?

I am novice in programming. My question why this function is called without tap when I use arguments? String _gesture = 'No Gesture Detected'; _printgesture(var gestureName) { setState(() { ...
s4nk37's user avatar
  • 103
1 vote
2 answers
69 views

Scala Anonymous Function Defined as Composition of Two Functions

I am a beginner in Scala, and currently studying the fascinating concept of anonymous functions. However, my following attempt at defining one results in a compilation error: def double(f:Int => ...
이희원's user avatar
  • 135
0 votes
2 answers
89 views

PHP 7.3 PHP Deprecated: Function create_function() is deprecated

I updated my php vesrion from 5.6 to 7.3 and now it showing an error PHP Deprecated: Function create_function() is deprecated in magiczoomplus/magiczoomplus.module.core.class.php on line 78 my code ...
Launch Athira's user avatar
1 vote
1 answer
341 views

"Candidate expects 1 argument, 2 provided" error with transform_reduce. Where are extra args?

I am trying to familiarize myself with lambda functions in C++. In my main, I am trying to turn a vector of ints into a string with the transform_reduce function from the C++ numeric library. After a ...
Joe Coon's user avatar
0 votes
1 answer
31 views

JS: Do anonymous functions automatically do data type conversion (casting) on parameters to match use in the function?

I'm writing a function to sort an object based on its keys, based on the example here: github The relevant lines: const unsortedObjArr = [...Object.entries(myObj)] const sortedObjArr = unsortedObjArr....
Travis Bemrose's user avatar
0 votes
1 answer
202 views

How to output data about tables in a loop in a postgresql database?

I need to output data about all tables in the format Table name | Number of columns | Number of fields using an anonymous function I do this: do $$ declare table_count integer := 0; columns_count ...
Efobo's user avatar
  • 1
0 votes
1 answer
23 views

Returning value from eventListener callback [duplicate]

My program contains 2 functions, one to fetch a random joke from https://api.chucknorris.io/ and the other to display the joke on a webpage. I think the problem lies in returning "joke.value"...
Luca Gilardenghi's user avatar
0 votes
2 answers
48 views

Multiple procedure assignment for self variable in one line

Is there any way a variable can be assigned from multiple procedures in one line? For example: $class_splits = explode("\\", $class_name); $short_class_name = $class_splits[count($...
ProtectedVoid's user avatar
0 votes
1 answer
62 views

Perform anonymous function on an object

This is probably very simple but I'm trying to perform an anonymous function on a list object (not the elements of a list). For example, is it possible to write the following as a single line? val a = ...
heathcliff-pang's user avatar
0 votes
1 answer
36 views

Using removeEventListener on function with parameter

Below is a module of my program to toggle page numbers. How can we use `removeEventListener' to remove functions with parameter? JSFiddle My JS part is document.querySelectorAll('button').forEach ( ...
Brijesh Roy's user avatar
0 votes
0 answers
42 views

NodeJS Custom Unit Test Automation Query

I have 2 Java Script files runTest.js and tests.js as below. This code is for custom automation of unit testing and it works. I am relatively new to Java Script syntax and unable to understand how ...
Mahesh H's user avatar
1 vote
1 answer
134 views

Return Type: Calling a function inside Vs outside `println()`

I'm new to Kotlin. I was experimenting with Anonymous functions a little bit until facing different outputs for the same concept using different approaches. First: Creating my Anonymous function: ...
Ahmedx288's user avatar
1 vote
0 answers
105 views

Is (,$arrr) the best way to pass a single array as an argument list to a powershell invoke-command cmdlet? [duplicate]

I want to pass an array to a PowerShell script block. This is the accepted method: $arr = 1..4; invoke-command -ScriptBlock { Param($li); $li | %{$_}} -ArgumentList (,$arr) From my investigations, ...
Nigel Davies's user avatar
  • 1,660
3 votes
2 answers
179 views

C function pointer: returning a function pointer from a function [duplicate]

I'm currently learning C, and trying to make my code more readable and easy to write, I found myself in need of creating a function (closure) in a function, and returning that function. Here's what I'...
uvero's user avatar
  • 81
1 vote
3 answers
29 views

Understanding variable scope with regard to anonymous functions in EventListeners

In the example below, it's the green square I'm interested in. I get that clicking on the red square returns the value of the variable set higher up. I get that clicking on the blue square returns the ...
Rounin's user avatar
  • 27.5k
0 votes
1 answer
74 views

Function currying in React instead anonymous function

Is there a benefit to use function currying instead of anonymous function (in terms of efficiency) inside events callbacks (onClick for example) when we need to pass params? const doSomthing = (arg1, ...
JovStern's user avatar
0 votes
0 answers
52 views

import machine ModuleNotFoundError: No module named 'machine'

import machine import time LED=machine.Pin(25,machine.Pin.OUT) while True: r=input('led ta che zamani cheshmak bezanad?') b=input('ta che zamani roshan bemanad?') a=input('ta che ...
user20583597's user avatar
0 votes
0 answers
153 views

Swift anonymous protocol implementation in function, and callbackFlow using async-await

How can I write an anonymous protocol inside a function in swift? In Kotlin, it is used like this: interface SomeInterface { fun interfaceFunction(someValue: Int) } fun someFunction() { val ...
MINIMIS BAE's user avatar

1
2 3 4 5
43