How to write records just in time when the value for id of something is changing ? id for each record when ture->false and false->true for some list?
for example table
id value
1 0
2 0
2 0
2 0
1 0
2 1 --> the only changes here
2 1
1 0
2 0 --> and here (node with id 2 changed 1 -> 0 )
1 1 --> node with id 1 changed 0 -> 1
result table
2 1
2 0
1 1
my idea is not functional and a bit weird, I’m thinking about functional or linq way of making the same.
let oop = ref (filteredsq
|> Seq.distinctBy(fun (node,v,k) -> k)
|> Seq.map(fun (node,v,k) -> k, false )
|> Array.ofSeq )
[for (node,value,key) in filteredsq do
let i = ref 0
for (k,v) in !oop do
if key = k && value <> v then
(!oop).[!i] <- (k,value)
yield node
i := !i + 1 ]
Thank you
I’m not sure if I fully understand your question, but the following gives the right output according to your sample. The idea is to first filter out values that don’t have the right key and then use
Seq.pairwaise(as in jpalmer’s solution) to find the places where the value changes:If you wanted to find changes for all different keys, then you could use
Seq.groupByto find all possible keys (then you wouldn’t need the first line infindValueChanges):(For your input, there are no changes in values for the key 1, because the value is always
1, 0)