Fold inverts the sequence order

The order of my sequence, array, etc. I tried converting List, Seq and Array to see if there are any differences, and in each case it returns order.

I have seq [noun] [verb] [ajective], for example, which is converted to strings and then added together. A sample response based on this pattern may be a “failed thug” rather than “thugs who work poorly”.

Any thoughts on why fold does this or how to get it to execute in the proper order?

let res = template |> Seq.map(fun pos -> 
                    let e = s |> PredictionEngine.GetRandom
                    pos |> PredictionEngine.GetBestPartOfSpeechWord e)
                    |> Seq.fold(fun acc w -> w.Text + " " + acc) ""
+4
source share
2 answers

I believe this is just a matter of reordering your last function:

Seq.fold(fun acc w -> acc + " " + w.Text) ""

. :

["Bandits";"Run";"Bad"]
|> Seq.fold(fun acc w -> acc + " " + w) ""
|> printfn "%s"
+7

, , .

["noun"; "verb"; "adj"]
|> String.concat " "

, , , .

+3

Source: https://habr.com/ru/post/1606828/


All Articles