문제

I have a Seq like this:

[(1, 0, 10); (5, 1, 10); (5, 0, 10); (8, 1, 10); ...]

And I want to decrease the third element in the tuple by one every time the second element is a 1

[(1, 0, 10); (5, 1, 9); (5, 0, 9); (8, 1, 8); ...]

I was thinking Seq.Fold b/c I need an accumulator but I am not sure how to implement. Am I on the right track?

도움이 되었습니까?

해결책

You just need a map:

[(1, 0, 10); (5, 1, 10); (5, 0, 10); (8, 1, 10); ...] 
|> List.map (function (first,second,third) when second = 1 -> (first,second,third - 1) | other -> other)

다른 팁

I was close, but using the wrong function

Seq.Scan does the trick....

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top