adding $ symbol for loop index, e.g. [i|i<-["a","b"],$i < 1] #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I implemented the "$" operator to allow retrieving the index of a loop. Here are some examples:
There are two things to discuss:
I also tried to implement a function which would take the iteration variable and return it's index, for example:
but I find this very complex to implement, because the "i" would have to change from an element of a list into kind of an object which contains also "iteration" information and the actual list element, and than the "index" function has to access the iteration part of this object, while everything else must access the element part:
may be there is a simple way to do it...
the other question is, why are we actually implementing this? if we only want to allow to take just part of a list we can do it either either the haskell way:
or the golang way:
I prefer to have both the
$operator together with the golang way of getting a slice of a list.The$is valuable for all kinds of more complex calculations/filtering, e.g. take the elements only on the every second position in the list, can be put in the result to remember a position of an element in the list, and so on...