closures Questions

6

Solved

I want to use a state variable (value) when a modal is closed. However, any changes made to the state variable while the modal is open are not observed in the handler. I don't understand why it doe...
Freudian asked 13/9, 2022 at 4:0

0

I can't figure out why I need a 'static bound in one case (bar) and not the other (baz): fn f<T>(_input: T) -> bool { false } fn bar<T>() -> Box<dyn Fn(T) -> bool + 'stati...
Farreaching asked 8/9 at 15:36

3

How should I document an anonymous function when it's passed as an argument? For example: // Call my_function(), passing 2 arguments. my_function( 'foo', function() { // Body of the anon function...
Flywheel asked 30/12, 2015 at 19:12

2

Solved

Basically I am going through the definition of closure functions which says - A function that can be referenced with access to the variables in its lexical scope is called a closure So I want to ...
Aconcagua asked 3/3, 2020 at 8:47

6

Solved

This SpriteKit action repeats by calling itself with a completion closure. It uses a closure, rather than an SKAction.repeatActionForever(), because it needs to generate a random variable each repe...
Acroter asked 25/6, 2014 at 17:27

4

Solved

I would like to replicate the behavior and ergonomics of taking a closure/function as an argument much like map does: iterator.map(|x| ...). I've noticed that some library code allows passing in a...
Oletta asked 17/3, 2020 at 7:12

4

Not sure if that's an issue with Swift, XCode or Alamofire but I recognized strange behavior on different places within my mixed Swift/Objc app. It only happens in parts which are written in Swift ...
Hindoo asked 26/1, 2015 at 15:23

3

Solved

Consider the following Go code (also on the Go Playground): package main import "fmt" import "time" func main() { for _, s := range []string{"foo", "bar"}...
Anecdotic asked 18/9, 2014 at 17:48

2

Solved

Would be possible to specify a default argument value when argument is a PHP closure? Like: public function getCollection($filter = function($e) { return $e; }) { // Stuff } Am i missing someth...
Photon asked 14/5, 2012 at 15:48

3

When providing callbacks to JavaScript using Closures, what's a better way to deal with avoiding freeing them? The wasm-bindgen guide suggests using .forget, but admits that that is essentially lea...
Forsythia asked 21/1, 2020 at 7:12

2

I've got this build.gradle file: repositories { maven { credentials { username "$artifactory_user" password "$artifactory_password" } url 'http://some.domain/artifactory/repo' } } publishi...
Capacitor asked 23/1, 2019 at 15:32

2

Solved

I attempt to implement a currying function similar to Functional Programming Jargon in Rust: fn add_origin(x: i32) -> impl Fn(i32) -> i32 { return move |y| { x + y }; } fn main() { let a...

9

Solved

I'm trying to create functions inside of a loop: functions = [] for i in range(3): def f(): return i functions.append(f) Alternatively, with lambda: functions = [] for i in range(3): functio...
Poock asked 7/8, 2010 at 19:4

11

Solved

I would like this to work, but it does not: #include <stdio.h> typedef struct closure_s { void (*incrementer) (); void (*emitter) (); } closure; closure emit(int in) { void incrementer...
Courtship asked 9/12, 2010 at 0:21

17

Solved

Could someone explain? I understand the basic concepts behind them but I often see them used interchangeably and I get confused. And now that we're here, how do they differ from a regular functio...

7

Solved

Are there pythonic ways to maintain state (for purposes of optimisation, for example) without going fully object-oriented? To illustrate my question better, here's an example of a pattern I use fr...
Panne asked 8/8, 2012 at 14:14

2

Solved

In this block of code below, I expect the output to be 0, 1, 2, 3,..., 9. However, only the output 10, 10,...,10 is produced. package main import "fmt" func adder() []func() { out := []func(){}...
Pleurisy asked 15/11, 2018 at 17:57

16

Solved

I am following the go tour on their official website and I have been asked to write a Fibonacci generator. Here it is: package main import "fmt" // fibonacci is a function that returns // a fu...
Bifilar asked 25/8, 2014 at 17:37

2

Solved

I have a code base with mixed Java and Groovy code. For iteration in the Groovy code, we tend to use closures: String[] strings = ["First", "Second", "Third"] strings.each { string -> println ...
Hilarius asked 11/3, 2013 at 9:13

4

I'm trying to write a light observer class in Swift (currently Swift 2). The idea is to use it within an Entity Component system, as a means for the components to communicate with one-another witho...
Dealer asked 28/6, 2016 at 10:29

2

Solved

I tried to use Delphi's syntax for anonymous methods: type fun = reference to function(): Integer; Fpc shows a syntax error: Error: Identifier not found "reference" What's the Free Pascal eq...
Aleron asked 17/10, 2011 at 20:19

3

Solved

Is there a way to pass a method as a parameter in Groovy without wrapping it in a closure? It seems to work with functions, but not methods. For instance, given the following: def foo(Closure c) {...
Affectionate asked 5/3, 2013 at 18:54

4

Solved

Let's say we have an array of objects like: var fruits = [ {name:"banana", weight:150},{name:"apple", weight:95},{name:"orange", weight:160},{name:"kiwi", weight:80} ]; I want to populate a "hea...
Footton asked 9/8, 2016 at 15:52

11

Solved

I met an interesting issue about C#. I have code like below. List<Func<int>> actions = new List<Func<int>>(); int variable = 0; while (variable < 5) { actions.Add(() =...
Roede asked 7/11, 2008 at 7:26

4

Solved

I am trying to build a control structure in a class method that takes a function as input and has different behaviors if a function is decorated or not. Any ideas on how you would go about building...
Barbour asked 29/7, 2021 at 23:40

© 2022 - 2024 — McMap. All rights reserved.