question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array addition and subtraction

See original GitHub issue

A way to add elements to (and remove elements from) an array would be really helpful. Eg something like

Array foo = range(5) # ie [ 0, 1, 2, 3, 4 ]
Array foo2 = foo + 6 # ie [ 0, 1, 2, 3, 4, 6 ]
Array foo3 = foo2 + range(2) # ie [ 0, 1, 2, 3, 4, 6, 0, 1 ]
Array foo4 = foo3 - 1 # Question: do we remove the first, the last, or both 1's?
Array foo5 = foo4 - [4, 6] # Remove both the 4 and the 6

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
fpichoncommented, Jul 13, 2018

I found some work around for people that need it :

Array[Int] x = [1,2]
Array[Int] y = [3]
Array[Int] z = flatten([x,y])

Hope it helps.

3reactions
patmageecommented, Jan 11, 2018

I think these are important features. I have come across situations where concatenating two result sets was annoyingly difficult. IE spinning up a new VM for a simple echo of two separate lists. So I definitely support this.

What I would disagree with the current suggestion is how the concatenation is performed. I think the types should match, which would then make this equivalent to a python extend operation as opposed to an append. In this case, even single elements should be wrapped as an array. To me this looks more consistent

Array[Int] x = [1,2]
Array[Int] y = [1,2] + [3]

Additionally, I do not think that we necessarily need the corresponding binary operator -. most languages do not support list subtraction as a form of removal. the other reasonable option would be to have an engine function which performs this ie:

Array[Int] x = [1,2]
Array[Int] y = [1,2] + [3]
Array[Int] z = remove(y,1)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Subtraction in the Array - GeeksforGeeks
Given an integer k and an array arr[], the task is to repeat the following operation exactly k times: Find the minimum non-zero...
Read more >
Matrix addition & subtraction (article) | Khan Academy
Learn how to find the result of matrix addition and subtraction operations. ... we can add and subtract them much like we add...
Read more >
Addition and Arrays (Grade 2) - Online Math Learning
These lessons, with videos, examples, solutions, and songs, help Grade 2 students learn how to use addition to find the total number of...
Read more >
2.2.8.1: Array Addition and Subtraction - Chemistry LibreTexts
For addition and subtraction, the array operations and the matrix operations are the same, so + and - can be regarded as either...
Read more >
C program to Add and Subtract of Two One Dimensional Array ...
C program to Add and Subtract of Two One Dimensional Array elements - C programming Example. This program will add and subtract two...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found