Forum Discussion

Dicken's avatar
Dicken
Icon for Post Prodigy rankPost Prodigy
7 hours ago

Accumulation, result error / not error

Hello all,

 

I'd like a bit of help as to how this works, the below returns and error, but if does work in the end, think i know why, and which I have put below, so this returns a list of errors, I think the first logical test returns true / false to the second must return and error ?

let   atext     = "the cat's bed, the dogs chased the cat, the cats' food,              the dog's bone and the cat's milk, the boy had a catapult",   old = {"cat", "dog"},   new = {"TIGER", "WOLF"},   removves = {".", ",", ";", "'", "s"},   replace =     let       split = Splitter.SplitTextByWhitespace()(atext)     in       List.Transform(         split,         (x) =>           List.Accumulate(             {0, 1},             x,             (s, c) =>               let                 test = Text.Remove(s, removves) = old{c}               in                 test           )       ) in   replace

But if I then take the test ( see below) true / false , and use it in the following I get the result  wanted,  not sure why this works any  insights as to how this works?   does the " if logical' re-set for the second pass of accumulate ? this is all i can think of .

let   atext     = "the cat's bed, the dogs chased the cat, the cats' food,              the dog's bone and the cat's milk, the boy had a catapult",   old = {"cat", "dog"},   new = {"TIGER", "WOLF"},   removves = {".", ",", ";", "'", "s"},   replace =     let       split = Splitter.SplitTextByWhitespace()(atext)     in       List.Transform(         split,         (x) =>           List.Accumulate(             {0, 1},             x,             (s, c) =>               let                 test = Text.Remove(s, removves) = old{c}               in                 if test then Text.Replace(s, old{c}, new{c}) else s           )       ),   result = Text.Combine(replace, " ") in   result    

 

No RepliesBe the first to reply