The order of my Sequence, array etc matters. I have tried converting between List, Seq and Array to see if there are differences and in each case it inverses the order.
I have a seq of [noun] [verb] [ajective] for example, which is transformed into strings and then folded together. A sample response given this template might be "bad run bandits" instead of "bandits run bad".
Any thoughts on why fold does this or how to get it to execute in the appropriate 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) ""
I believe this is just a matter of changing the order of your last function to:
Seq.fold(fun acc w -> acc + " " + w.Text) ""
Like this the new itens get concatenated to the end of the old ones. A minimum example of this working can be seen in the following snippet:
["Bandits";"Run";"Bad"]
|> Seq.fold(fun acc w -> acc + " " + w) ""
|> printfn "%s"
If you have such common job as concatenating strings I recommend using functions from library.
["noun"; "verb"; "adj"]
|> String.concat " "
On daily basis work, I think, there are not so many problems that require writing custom folding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With