You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In python, you can do [i ** 2 for i in range(10)] to iterate through each value in range and square each one and get a list of squares all in one expression. I propose a similar syntax for expr:
[v**2for _, v:=range0..9]
This would return the slice of all the numbers from 0 to 9 squared.
Another thing you could do is a conditional comprehension, for example
[[i, v] fori, v:=range [1, 4, 7, 2, 3] ifv<=5]
This would return a [][]int of the numbers and indexes of those numbers where the number is less than or equal to 5. In this case it would be [[0, 1], [1, 4], [3, 2], [4, 3].
This feature would make this package more powerful and greatly increase the potential of it, as currently there is no way to return a slice outside of the range operator, which is limited.
The text was updated successfully, but these errors were encountered:
I'm thinking about adding comprehensions too. But I don't like nested comprehensions, as it difficult to read it.
Also I think before adding comprehensions will be cool to think about map/apply functionality and closures/lambdas.
On opposite side, without comprehensions expressions can stay simple. In our project we heavily rely on expr and implemented a lot of useful helpers for iterating or complex login. In expressions just combining them.
In python, you can do
[i ** 2 for i in range(10)]
to iterate through each value in range and square each one and get a list of squares all in one expression. I propose a similar syntax for expr:This would return the slice of all the numbers from 0 to 9 squared.
Another thing you could do is a conditional comprehension, for example
This would return a
[][]int
of the numbers and indexes of those numbers where the number is less than or equal to 5. In this case it would be[[0, 1], [1, 4], [3, 2], [4, 3]
.This feature would make this package more powerful and greatly increase the potential of it, as currently there is no way to return a slice outside of the range operator, which is limited.
The text was updated successfully, but these errors were encountered: