"Destructuring allows you to bind a set of variables to a corresponding set of values anywhere that you can normally bind a value to a single variable" ("Common Lisp the Language").
Questions tagged [destructuring]
1338 questions
0
votes
1 answer
How does works the destructuring array with generator functions?
I find this example and I was surprising the way that the eventually values of the generator are get from the generator. This is the code:
function* foo() {
yield 'a';
yield 'b';
yield 'c';
}
const [...values] = foo();
Based on my…

Gonzalo Pincheira Arancibia
- 3,483
- 1
- 23
- 42
0
votes
0 answers
Generic macros? (as extension of generic functions)
Paul Graham in On Lisp, Ch 18, presents a number of interesting macros for destructuring various objects, extending the basic tree destructuring offered by destructuring-bind. For example, a macro for destructuring the fields of a structure object…

davypough
- 1,847
- 11
- 21
0
votes
0 answers
Javascript destructuring of a supertest HTTP API response
I am running Supertest, Jasmine and Chai to auto-test an HTTP API.
Expectations like this work:
.expect( function(response) {
expect(response.body.minVersion).to.equal(undefined)
…

cham
- 8,666
- 9
- 48
- 69
0
votes
0 answers
What is the proper way to type destructured arrays and objects in Typescript?
So I am using typescript and node, currently have it able to compile down to js. As I learn more about strictly typing js, I am curious as how the proper way to type declarations that are destructured. I cannot seem to find a proper link or know…

cheussy
- 361
- 2
- 11
0
votes
1 answer
How to destructure array of objects?
Given this JSON object:
{
"Person": {
"UID": 78,
"Name": "Brampage",
"Surname": "Foo"
},
"Notes": [
{
"UID": 78,
"DateTime": "2017-03-15T15:43:04.4072317",
"Person": {
…

Brampage
- 6,014
- 4
- 33
- 47
0
votes
1 answer
Can't Access Destructuring Assignment from Complex Object
Given the input value:
input =
name:'Foo'
id:'d4cbd9ed-fabc-11e6-83e6-307bd8cc75e3'
ref:5
addtData:'d4cbd9ed-fabc-11e6-83e6-307bd8cc75e3'
data:'bar'
When I try to destructure the input via a function like this:
simplify:…

jusopi
- 6,791
- 2
- 33
- 44
0
votes
1 answer
How to iterate nested PersistentArrayMap in Clojure/Script
After executing a query against the db, the return of the fuction is the list of maps:
({:id 1 :name "Book 1" :category "Drama"}
{:id 2 :name "Book 2" :category "Drama"}
{:id 3 :name "Book 3" :category "Poetry"}
{:id 4 :name "Book 4" :category…

graaf
- 15
- 1
- 7
0
votes
3 answers
Default argument value of a function, destructuring assignment
Guys, some theory work here.
There's a function -
function lol( { x = 10 } = {}, { y } = { y : 10 } ) {
console.log( x, y )
};
Things are getting hairy here
lol(); // 10, 10
lol( {}, {} ); // 10, undefined
Why am i getting undefined after…

Sergio Nikolaev
- 679
- 8
- 16
0
votes
1 answer
Parameter Object Destructuring with Required Values and Empty Object
Using ES6 parameter object destructuring we can require the presence of certain properties, as well as, provide default values. Dr. Axel Rauschmayer said in the Six nifty ES6 tricks article that parameter default values are only evaluated when they…

Francisco Maria Calisto
- 2,841
- 4
- 22
- 54
0
votes
1 answer
Passing destructured args through macros
I'm having some trouble writing macros which use destrucutred arguments. Here is an example:
(defmacro defny
[n args & forms]
`(defn ~n ~args ~@forms))
(defmacro defnz
[n f args & forms]
`(defn ~n ~args
(do
(~f ~@args)
…

Jonathan Viccary
- 722
- 1
- 9
- 27
0
votes
2 answers
How to assign a keys of an array as a function's parameters?
I have a JavaScript module that exported with arrow function with 3 parameters, the following example:
// getMonth.js module
export default (date, type, ...rest) => {
// Represent this return exmaple
return date + ' ' + type + ' ' +…

Masoud
- 1,008
- 1
- 9
- 22
0
votes
2 answers
Can I declare an array of values that are nested inside a collection of objects without writing a loop?
Maybe a spread operator or destructuring instead?
Instead of writing this function and calling it with the collection to create an array
function namesArray(group) {
let names = [];
group.values.forEach( (value) => {
…

Nick
- 73
- 6
0
votes
2 answers
Destructuring a function in a list
I have the following two test cases in Clojure, one destructuring a vector, and one destructuring a list:
user=> ((fn [[a op b]] (op a b)) [1 + 2])
3
user=> ((fn [[a op b]] (op a b)) '(1 + 2))
2
Why is the symbol + evaluated in the first test…

GLee
- 5,003
- 5
- 35
- 39
0
votes
2 answers
Can you create an object when destructuring function arguments?
Basically I'm trying to see if I can do this:
var state = {
lastMessage: {
owner: 'lastMessageOwnerID'
},
owner: 'currentMessageOwnerID'
}
function isSameMessageOwner ({ lastMessage, owner: currentMessage: { owner } }) {
return…

Alex Cory
- 10,635
- 10
- 52
- 62
0
votes
1 answer
Is [{:keys [:a]}] or [{:keys [a]}] more idiomatic destructuring?
What are the differences between the two following forms?
(defn abc [{:keys [:a]}] a)
(defn abc [{:keys [a]}] a)
Is there one that is more idiomatic?

nha
- 17,623
- 13
- 87
- 133