List traverse runs from right to left
See original GitHub issueDescription
It looks like List.traverse runs from right to left, it should be from left to right according to the document.
Repro steps
Below code could reproduce this problem
let mapper (v: int) =
Console.WriteLine(sprintf "mapping: %d" v)
Result.Ok v
let test v =
List.traverse mapper v |> Result.map List.last
test [1; 2; 3]
Expected behavior
It should prints
mapping: 1 mapping: 2 mapping: 3
Actual behavior
It prints in the reverse order
mapping: 3 mapping: 2 mapping: 1
Related information
The code runs with FSharpPlus 1.1.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Traverse a list in reverse order in Python [duplicate]
Use list. reverse() and then iterate as you normally would. for what ever it's worth you can do it like this too. very...
Read more >Traverse a list in reverse order in Python
This post will discuss how to traverse a list in reverse order in Python without modifying the original list. 1. Using built-in reversed()...
Read more >Iterating Backward Through a List
In this quick tutorial, we'll learn about various ways in which we can iterate backward through a list in Java.
Read more >Java Program to Traverse Through ArrayList in Reverse ...
There are several methods by which we can Iterate and print List in reverse direction listed below. Method 1: (Using ListIterator). 1. Declare ......
Read more >ZigZag Tree Traversal
Whenever the current level order is from left to right, push the nodes left child, then its right child to the stack nextlevel....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess we can even do it in 2 passes with this version:
What do you think @gusty ?
EDIT: I’ve ran simple performance tests:
and the results show that this implementation seems to have similar performance
Sure, but note that it’s not a good practice, even in F#, to include sideeffects in let’s say a
map
function call, it’s always better and more readable (and less surprising) to use a dedicatediter
to perform side-effects. The same applies fortraverse
.Anyway, let’s try to come up with a solution that fixes the order without compromising performance too much.