Questions tagged [closures]
A closure is a first-class function that refers to (closes over) variables from the scope in which it was defined. If the closure still exists after its defining scope ends, the variables it closes over will continue to exist as well.
closures
9,004
questions
0
votes
1
answer
30
views
Using @autoclosure in Swift: Can It Behave Like Overloaded Functions?
I have a function that uses @autoclosure. Is there a way to make @autoclosure behave similarly to overloaded functions, so it automatically knows which syntax is right for variables like in my case?
...
0
votes
1
answer
67
views
In angular is there any way are we using closure concept?
I was going through the resources and found that accessing values from classes using getter methods is a form of closure. Since the resources are AI-generated, I'm verifying whether this is indeed a ...
-1
votes
1
answer
27
views
Question on borrowing in Rust with closures [duplicate]
I am trying a sample program in Rust to understand closures as follows. But I get in error for the line "After defining closure" below.
let mut list = vec![1, 2, 3];
println!("...
0
votes
0
answers
36
views
Determining if two functions appear in the same place in source code
Say I have the following JS:
function counter() {
var i = 0;
return function() {
return i++;
}
}
var counter1 = counter();
var counter2 = counter();
Here, counter1 !== counter2 because ...
1
vote
1
answer
53
views
React state gets updated but changes are not reflected in an event listener called programatically
This is a socket.io chat app, where I am trying to add a keyboard shortcut. I am listening for the "keydown" event and calling the button click listener function (which is also throttled) ...
0
votes
0
answers
25
views
Is it possible to modify (monkey patch) internals function of a function imported in an imported function in javascript?
Is it possible to modify the behavior of functions called inside a closure in js?
Lets say i have this code which i am importing from a library:
// b.js
export const b = () => {
console.log('b') ...
-2
votes
1
answer
44
views
In Kotlin, is it possible to change the reference in a closure?
The idea is that you pass a lambda to a class and you want to change the implementation after it is passed to the class, but the class does not expose any way to update the lambda's implementation.
As ...
0
votes
1
answer
84
views
How can I pass a reference to a closure in Rust?
I am using wry to spawn a few web views. Each view has a on_page_load_handler. Inside the handler I need to access the web view to e.g. navigate to another website. Sadly I fail to pass the web view ...
0
votes
1
answer
53
views
PowerShell Generic List .Where() performance with variable expansion from higher scope
Given a hashtable called $derivedValues, and a variable that requires variable expansion, I am seeing some interesting performance issues.
Given:
$rule.opnd1 = 'uninstallString'
$rule.opnd2 = 'MsiExec....
2
votes
1
answer
87
views
Powershell closure for .Where() in a string variable
I have a Generic List of hash tables derived from Uninstall keys in the registry, which I need to search. Each list member is an ordered dictionary containing these keys. The actual value of each key ...
1
vote
1
answer
89
views
JS: inject into BoundFunctionObject for bookmarklet script
Suppose I am writing a bookmarklet script to modify a webpage. Most websites (using webpack, etc) follow a structure something like this:
<html>
<script type="text/javascript"&...
0
votes
1
answer
31
views
What are "encrypted closures" in Next.js and how do they work?
Learn Next.js mentions "encrypted closures" as an important security mechanism as part of Server Actions, where some of your Next.js app runs on the server instead of in client-side ...
2
votes
4
answers
75
views
useEffect function is not working as expected
import React, { useState, useEffect } from 'react'
function Counter() {
const [count, setCount] = useState(0)
const incCount = () => {
console.log("count ", count)
// ...
-1
votes
1
answer
44
views
What is the correct way to declare, instantiate and unwrap an optional closure?
I have a class CommentView that has an optional closure (for simplification purposes, I've cut down the code to its bare basics to make it easy for the reader):
struct CommentView: View
{
@State ...
0
votes
0
answers
45
views
Comparing two closures for identity
I have an array of closures for filtering objects with array_reduce:
function test1(/* params */): bool { /* code returns true or false */ }
function test2(/* params */): bool { /* code returns true ...