Questions tagged [closures]

1

votes
1

answer
103

Views

Frank copula parameter minimization

I am attempting to calculate the Frank copula parameter given Kendall's tau. Here is the problem I am attempting to solve numerically in R: So far, this is the code I have: copula
StatGuy45
1

votes
2

answer
156

Views

How to escape a value with a throw '() throws -> Bool' is not convertible to 'Bool'

I'm new in swift and I've been probably for more than an hour around this. I make a request to a webservice, and now i want to act according to the response code (200 Ok) or other but I can't understand the syntax for returning a value and throwing the exception. typealias ThrowableCallBack = () th...
João Serra
1

votes
0

answer
26

Views

Guaranteed to have no more than one closure object per local function?

I wonder if I can make multiple delegates from a single local function and rely on them to be all equal? In other words, if I make multiple delegates referencing the same local function, are they all equivalent? Or should I make sure to only create one if I need them to be equal? Of course, assuming...
relatively_random
1

votes
0

answer
45

Views

How to use local variables in closures during performDrop

I'm working my way through the Stanford CS193P Course on iTunesU. Stuck on this one part - There's one section where the instructor has the following comment: When a drop happens, you'll have to collect both the aspect ratio (from the UIImage) and the URL before you can add an item. You could do th...
Eduard Lev
1

votes
0

answer
91

Views

Zend Framework Serialization of Closure not allowed

I'm having difficulty finding an answer to this issue specifically for zend framework on the internet. I'm getting an error of Serialization of Closure is not allowed. The issue I have is that its just the zend internal code, not any of my code. I know this because i used the zend skeleton applicati...
jkushner
1

votes
1

answer
71

Views

Spock reusing generic closure

I have this code in Spock: then: 1 * dao.getByValue(Something.ONE, _ as String) >> {Something smth, String value -> return createSomething(smth).withValue(value).build() } It doesn't look exactly like that, but you get the point. I want to return an object based on arguments passed to the method, in...
Shadov
1

votes
2

answer
37

Views

Re:Javascript closure. How the variable inside of the mother object become the same as the mother object?

I have a question about public variable and closure. In the following code, how come the 'temp' variable inside of the mother object can be used like the mother object? For example, in the following code, if you type console.log(pizzaA.getToppings()); You can get '3' A bit confusing because if y...
1

votes
1

answer
70

Views

How can Java versions older than 8 not support Closures? [duplicate]

This question already has an answer here: Closure in Java 7 [closed] 7 answers I read that Java 8 supports Closures, but I just wanted to know that as any function inside a class can access a global variable, so how can Java previously didn't support Closures ?? See below example. public class Hell...
Sudhanshu Gaur
1

votes
0

answer
25

Views

Why am i not able to see “Closure” in chrome dev tool?

BTW this is the chunk i have used to check: function outerFunction () { const outer = `I see the outer variable!` function innerFunction() { console.log(outer) } return innerFunction } outerFunction()(); Do i need to enable something in settings or any extension is required or whatever. Any help wou...
indar
1

votes
0

answer
33

Views

What mean *@param array|string|\Closure $middleware

I'm in Laravel 5.6, Controller.php abstract class with Illuminate\Routing namespace and I would like know what kind of parameter is specified in line 19 to declared method in line 23. I know what closure and middleware are but I don't know what this line means. 16 /* 17 * Register middleware on the...
Fahico98
1

votes
0

answer
30

Views

what's the diff. between the nested and Closure function in python

can you please tell me the diff. between the nested and Closure function?? With simple examples?? Thank you! I can't not understand perfectly the difference.
Enami
1

votes
1

answer
261

Views

MVVM - using closures to bind a ViewModel with a DataSource: capture list needed?

I have a viewController keeping a (strong) reference to its viewModel lazy private var viewModel: ListViewModel = { return ListViewModel() }() override func viewDidLoad() { super.viewDidLoad() initViewModel() } private func initViewModel() { viewModel.onModelChange = { [weak self] () in DispatchQueu...
AppsDev
1

votes
1

answer
31

Views

The below closure example not returning properly

I am trying to implement the below javascript code using closures and I get the output like this. Here the whole function is printed in the browser `function apple(){ var test1 = ' '+ ' '+ ' This is apple'+ ' '+ ' '; return test1; }` Desired output: I only want 'This is apple' to be printed and not...
Jeril CJ
1

votes
1

answer
38

Views

What is the difference between retain cycle in these closures? Standard closure vs object initialized closure

I understand the typical retain cycle with a closure when referencing self within the closure, but is there a reason the label does not produce a retain cycle? I've tested commenting the testClosure out vs commenting the label out and only the testClosure produced a retain cycle class TargetVie...
jo1717a
1

votes
1

answer
33

Views

Remove array index if instance object value and array value are the same

I have an array named var geoLocList = [GeolocationModel]() and an object named var geoLocs = GeolocationModel() The values of geoLocs appended to geoLocList. The problem is, I'm trying to replace index in geoLocList with the latest value of geoLocs according to the same id. I'm still a newbie in i...
1

votes
3

answer
55

Views

jQuery Closure in For Loop [duplicate]

This question already has an answer here: JavaScript closure inside loops – simple practical example 42 answers I am familiar with JavaScript closures. I discovered closure issues while working on my own projects, years ago. I have also included the famous for-loop-button question while interview...
Dev
1

votes
2

answer
23

Views

Set class/prototype variable from jQuery function

Can somebody help me to understand how in this situation I can push values from $.each function into this.books array? let Library = function ( name ) { this.name = name; this.books = Array(); }; Library.prototype.addBook = function ( book ) { if( Array.isArray( book ) ) { $.each(book, function() {...
1

votes
0

answer
106

Views

What is the Javascript [[Environment]] Property?

I am reading Secrets of the Javascript Ninja and am trying to figure out where the closure variables of a function are stored.[[Environment]] property available on the function identifier: Whenever a function is created, a reference to the lexical environment in which the function was created is sto...
VSO
1

votes
3

answer
32

Views

Javascript Closures. Lexical vs function context. [duplicate]

This question already has an answer here: What is the scope of variables in JavaScript? 25 answers My question is why the following code prints 1 instead of 500; When the callback is invoked and it doesnt find the variable count, doesnt it first looked at the context of func1 ? function func1(cb)...
sco
1

votes
0

answer
274

Views

Programmatically accessing [[Scopes]] (closure variables) through Chrome DevTools API or panel? (Not at breakpoint)

In 2014, it was not possible for JS code to access variables inside a closure from outside the closure. Since then, Chrome's internals have changed to use [[Scopes]] instead of Closure. Is it now (2018) possible for Chrome DevTools to read [[Scopes]] programmatically? If so, is there an existing...
cxw
1

votes
0

answer
39

Views

JSON issue with looping inside closure

I have to pull JSON data from a few different website endpoints in order to get a full view of the objects I'm working with. In order to do so, I am using the downloadJSON code below. This works OK, except whenever I create a for loop within downloadJSON(){ }, the amount of iterations in the loop...
greg42627
1

votes
0

answer
28

Views

Unable to save data from anonymous function [duplicate]

This question already has an answer here: How do I convert an existing callback API to promises? 18 answers How do I return the response from an asynchronous call? 34 answers I'm currently refactoring some code, and I'm running into a problem. I am trying to return the value from inside an anonymo...
Ollie
1

votes
0

answer
78

Views

Are closures implemented as classes in the Swift compiler? Is a common closure a subclass of a throwing closure?

In Swift, the only reference type available to a programmer is a class. We know that closures are objects as they store references to variables captured in the parent scope. Closures are also reference types, according to Apple's Swift Programming Language Guide. You can see that assigning a closure...
Max Desiatov
1

votes
0

answer
30

Views

PHP [closures] [override method runtime] How Improve this wrapp

I wrote this code for override a object method: class A{ public function foo(){ echo 'foo'; } } $a = new A(); $a->foo = function(){ echo 'don't work'; } $a->foo(); but the above code doesn't work i tried use a Closure but it didn't work. so i wrote this utility class in my project, the class work a...
Gytree
1

votes
1

answer
56

Views

How to create a generic completion closure?

I have the following protocol: protocol RESTAPIprotocol { associatedtype T: Object, Decodable } extension RESTAPIprotocol { func getList(sinceSyncToken: String = '', pageLimit: Int = 100, progress: Moya.ProgressBlock? = nil, completion:@escaping (_ list: [T]?, _ error: AppError?) -> Void) { ... } an...
Sebastian Dwornik
1

votes
1

answer
64

Views

Why do I get an “Access to disposed closure” warning with this code

I have the following code (using ImageSharp): using (var I = Image.Load(Picture)) { // calculate the hash var T = Task.Factory.StartNew(() => CalculateHash(I)); var Hash = T.Result;
Thomas
1

votes
1

answer
48

Views

Convert a non-escaping closure to an escaping one or the other way

I'm creating a template pattern to easily switch between Nimble And XCTAssert for my Unit Tests. So I have a protocol protocol Assertable { func notNil(_ expression: @autoclosure () throws -> Any?, file: StaticString, line: UInt) } XCTAssert implementation of not nil is like so: func XCTAssertNotNil...
Kalzem
1

votes
1

answer
187

Views

get the value of variable outside of completion block from closure in swift 4

I have a project written in swift 4. It produces nil when I try to access the value inside of the closure. Here is my code: import UIKit import SwiftyJSON class TchatViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { let appDelegate = UIApplication.shared.delegate as! App...
Swift Guy
1

votes
0

answer
20

Views

Closure issue - Nested for loops only print out once

Here is a very well know post on stack overflow JavaScript closure inside loops – simple practical example but I can't seems to get my head around with it. My little script below successfully print out each location on the screen. When I click on the marker on the maps it will bring up the pop up...
shafe
1

votes
0

answer
74

Views

is.na() applied to non-(list or vector) of type 'closure'

I have the following distribution function (F): F=0)) (1+ (-1)/(1+t^2)) else (0) } When plotting, it looks as follows: plot(Vectorize(F), xlim=c(-100,100), main='Distribution function', xlab='t', ylab='F(t)') I am trying to calculate the 0.25,0.75 and 0.50 quantiles for this F distribution, but I ge...
Irene
1

votes
0

answer
53

Views

Jenkins + groovy: weird thing of array and list and closure

Anyone know why this problem happens in jenkins? (I tested it in an free style pipeline) // output: [Ljava.lang.String;@eb1da95 print 'a,b'.split(',') // output: [a, b] print 'a,b'.split(',').toList() this cause error: print 'a,b'.split(',').any{ it -> true } But this works. Output: true print '...
osexp2003
1

votes
0

answer
38

Views

Adding elements of multiple arrays together in swift 4

Is there a way to add elements of multiple arrays together in swift, without for loops? For the instance of 3 arrays: let arrayA: [Float] = [1,2,3,4] let arrayB: [Float] = [10,20,30,40] let arrayB: [Float] = [100,200,300,400] I'm looking for an output of [111,222,333,444] I know this can be accompl...
greg42627
1

votes
0

answer
27

Views

Constants Local to Member Functions

I am looking for a good solution for where to put (semantic) constants inside a class that are only relevant to some specific member function. I don't want to initialize these constants every time I call the member function, but I also do not want to clog up the class with them: class C: def __init_...
lo tolmencre
1

votes
0

answer
49

Views

Can you access a swift subscript as a closure?

Given the following class in swift: public class Foo { public init () { } public subscript (index: Int) -> Int { get { return index } } public func intIdentity (val: Int) -> Int { get { return val } } } Clearly I can access intIdentity as a closure by using something like this: let foo = Foo() let c...
plinth
1

votes
2

answer
37

Views

Manipulating enclosing environment of a function

I'm trying to get a better understanding of closures, in particular details on a function's scope and how to work with its enclosing environment(s) Based on the Description section of the help page on rlang::fn_env(), I had the understanding, that a function always has access to all variables in it...
Rappster
1

votes
0

answer
38

Views

Get value from inside callback inside new Class in Javascript

I've run into an issue where I'm unable to get the value I need from inside a callback that's passed to an instantiation of a JavaScript class. let value; const mutationObserver = new MutationObserver((mutations) => { return values.map((mutation) => { value = mutation.target.childElementCount; retur...
zero_cool
1

votes
0

answer
37

Views

In build.gradle how to extract and reuse Maven repository configuration?

I've got this build.gradle file: repositories { maven { credentials { username '$artifactory_user' password '$artifactory_password' } url 'http://some.domain/artifactory/repo' } } publishing { repositories { publications { maven(MavenPublication) { from components.java } } maven { credentials { user...
Harold L. Brown
1

votes
0

answer
44

Views

Swift: Why does a function returned from another function can't have default values? [duplicate]

This question already has an answer here: Xcode 8 :function types cannot have argument label breaking my build 5 answers Why Swift throws error when using optional param in closure func? 1 answer Let's say we have a function with defalut parameter values: // function with default parameter values...
lochiwei
1

votes
2

answer
48

Views

Return statement inside a closure

Do following return statements have any significance inside closure. Do they return as intended? fetchAPI() { (result, error) in if error != nil { // Print error return } else { if result?.data != nil { if (result?.success)! { // Do stuff } } else { // Print error return } } }
Vaughn

View additional questions