How do JavaScript closures work?

How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures...

What REALLY happens when you don't free after malloc?

This has been something that has bothered me for ages now. We are all taught in school (at least, I was) that you MUST free every pointer that is allocated. I'm a bit curious, though, about the...

What do lambda function closures capture?

Recently I started playing around with Python and I came around something peculiar in the way closures work. Consider the following code: adders=[None, None, None, None] for i in [0,1,2,3]: ...

What is a practical use for a closure in JavaScript?

I'm trying my hardest to wrap my head around JavaScript closures. I get that by returning an inner function, it will have access to any variable defined in its immediate parent. Where would this...

How to Deep clone in javascript

How do you deep clone a JavaScript object? I know there are various functions based on frameworks like JSON.parse(JSON.stringify(o)) and $.extend(true, {}, o) but I don't want to use a framework...

Which version of php added anonymous functions

In manual there is create_function function and you can pass result from that function to array_map, I thought that that is the only way to have something like anonymous functions and closures,...

Reference - What does this error mean in PHP?

What is this? This is a number of answers about warnings, errors, and notices you might encounter while programming PHP and have no clue how to fix them. This is also a Community Wiki, so everyone...

Why is bind slower than a closure?

A previous poster asked https://stackoverflow.com/questions/6397096/function-bind-vs-closure-in-javascript-how-to-choose and received this answer in part, which seems to indicate bind should be...

How to inject variable into scope with a decorator?

[Disclaimer: there may be more pythonic ways of doing what I want to do, but I want to know how python's scoping works here] I'm trying to find a way to make a decorator that does something like...

Why does an open server-sent event prevent other SSE, POST or GET?

When I open a SSE (a simple one), all the others ajax requests (POST, GET, SSE) are waiting for the closure of the SSE. Does it normal? What should I do to let requests run in same time? Thanks.

Gradle - throwing errors during plugin apply - "Failed to notify ProjectEvaluationListener.afterEvaluate()"

I wish to throw an error during the plugin apply method, in order to inform the user of missing settings (and help them fix it). I'm seeing the following error repeatedly: Failed to notify...

What does %>% function mean in R?

I have seen the use of %>% (percent greater than percent) function in some packages like dplyr and rvest. What does it mean? Is it a way to write closure blocks in R?

Difference between returning Void and () in a swift closure

Whats the difference between these closures? let closureA: () -> () and let closureB: () -> Void

Laravel 5 on php artisan config:clear generated Closure::__set_state() error

My code in on production and I ran php artisan config:clear After that, my code was not running. The index pages and all other pages went white screen and gave 500 internal server error in...

How can I co-sort two Vecs based on the values in one of the Vecs?

I have two Vecs that correspond to a list of feature vectors and their corresponding class labels, and I'd like to co-sort them by the class labels. However, Rust's sort_by operates on a slice...

What's a good example of an escape closure in Swift?

I'm reading the Swift programming language manual and it mentions an escaping closure. With regards to escaping closures, I don't know what they mean by "the closure is passed as an argument to...

php - convert a method to a closure

I want to know is there any way to convert a method to a closure type in php? class myClass{ public function myMethod($param){ echo $param; } public function myOtherMethod(Closure $param){ ...

Wait for completion handler to finish - Swift

I am trying to check if UserNotifications are enabled and if not I want to throw an alert. So I have a function checkAvailability which checks multiple things, including the UserNotification...

Information-hiding in Groovy (using closures? naming conventions?)

This follows from my unsuccessful attempt to find an answer to this question from 2014. It's not clear to me whether there might in fact be some techniques in Groovy to use closures, specifically,...

Using closures as parameters without trailing closures Swift

When using trailing closure syntax it seems quite easy to pass a function as a parameter of another function. However I want to do this WITHOUT using the trailing closure syntax func...

Stream/Bloc/Repository/Firebase data flow Flutter

I'm starting with flutter as I want to port my swift app to Flutter, but I'm getting stuck understanding the pattern Bloc/Repository/Firebase as I'm following the tutorial...

What is the Lexical Scope in dart?

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...

Generic UIView Initializer with closure in swift

I want to write a generic UIView initializer so I can initialize UIViews by passing the configuration closure in initializer.What I want is the below syntax to work for all UIView subclasses. let...

Getting error for artisan commands ( In routes-v7.php Call to undefined method Closure::__set_state() )

I have upgraded Laravel version from 5.7 to 8.34. I'm getting this error for all artisan commands.

Combine: Is this a good technique for a custom publisher?

I'm playing about with writing a custom Combine publisher in order to better understand how I can turn various classes into them. Admittedly this is not something I want to do a lot, I just want...

How to capture local variable inside an async closure in Swift?

I have the following code in Swift 5.5 and iOS 15 func getReviewIds() { var reviewIds: [Int] = [] Task { let ids = await getReviewIdsFromGoogle() ...

html2pdf - Too many tag closures found for [table]

we are creating a PDF in php using html2pdf. This also works quite well. However, we fetch data from the DB into an html table. If it becomes too much data, we need a second page. But this is not...

Errors broke app after updating to Xcode 13

I'm working in SwiftUI App Lifecycle. I just updated Xcode and am getting a bunch of errors on an app that has been working fine on a slightly older version of Xcode...In...

Telling two paths apart in a road network graph?

This is a graph theory problem on a real dataset. I have a dataset of roughly 100M points, of camera sightings of cars over time in a city. They can be thought of as { camera ID, license plate ID,...

What is the relation between a function with free variables and a closure?

Are free variable(s) in a function the thing(s) "closed" upon in a closure?