一个递归解决合并问题

@fx()递归问题

let 
     源 = {{1..3},{2..6,{1..3,{1..3,{2..6}}}},{4..9,{1..6,{1..6,{1..6,{1..6}}}}}},
     fx=(x)=>List.Transform(x,each if _ is number then Text.From(_) else @fx(_)) , 
     ft =(y)=>List.Combine(List.Transform(y ,each if not(_ is list ) then {_} else @ft(_))) 
   in  Text.Combine(ft(fx(源)))

file
经过群里的花生大佬优化后更加简洁了,太妙了!!!
收藏是非常必要的:

= let fx=(x)=>List.Combine (List.Transform(x,each if _ is list then @fx(_) else {Text.From(_)})) in Text.Combine(fx(源))

file
深入清洗:

= let 
源 = {{1..3},{2..6,{1..3,{1..3,{2..6}}}},{4..9,{1..6,{1..6,{1..6,{1..6}}}}}},
fx=(x)=>Text.Combine (List.Transform(x,each if _ is number  then Text.From(_)  else @fx(_))) 
in fx(源)

难道真的已经到了最高境界吗?没有

= let 源 = {{1..3},{2..6,{1..3,{1..3,{2..6}}}},{4..9,{1..6,{1..6,{1..6,{1..6}}}}}},
fx=(x)=>List.Accumulate(x,"",(x,y)=> if y  is number then x&Text.From(y) 
                                        else x&@fx(y) )
in fx(源)

file
Power Query是个不断的修改,测试,探索的过程?

让我们来分析一下处理过程
源 = {{1..3},{2..6,{1..3,{1..3,{2..6}}}},{4..9,{1..6,{1..6,{1..6,{1..6}}}}}}
这个层级太多看了容易头晕
file
这个 源={1..3}列表内每个元素都是数,所以执行了if...then ,if ...else 没有执行条件
现在我将源改一下,源={1..2,{1..3}} 外面再套个列表,这样列表的第三个元素不符合条件,就会执行if ...else
让我们执行一遍代码,
首先遍历整个列表,
第一个元素1,符合条件,执行List.Transform(x,each if is number then Text.From()
第二个元素2符合条件,执行 List.Transform(x,each if is number then Text.From()
第三元素{1..3}是个列表,不符合条件,执行 if ...else @fx(),@fx()是什么鬼,就是对新的列表进行if ...then ..的操作
用新列表{1..3} 替换 {1..2,{1..3}}列表 执行炒作,由于{1..3}元素没有列表,所以执行Text.Combine ( if is number then Text.From())
源 =Text.Combine (List.Transform( {{1..3},{2..6,{1..3,{1..3,{2..6}}}},{4..9,{1..6,{1..6,{1..6,{1..6}}}}}},....))
1-1=Text.Combine (List.Transform( {1..3},....))二个函数完全执行,结果是"123"
2-1=Text.Combine (List.Transform( {2..6,{1..3,{1..3,{2..6}}}},....))这个Text.Combine 函数没有执行条件,
2-2=Text.Combine (List.Transform( {1..3,{1..3,{2..6}}},....))这个Text.Combine 函数没有执行条件,
2-3=Text.Combine (List.Transform( {1..3,{2..6}},....))这个Text.Combine 函数没有执行条件,
2-4=Text.Combine (List.Transform( {2..6},....))二个函数完全执行,结果是"23456"
3-1=Text.Combine (List.Transform({4..9,{1..6,{1..6,{1..6,{1..6}}}}} ,....))这个Text.Combine 函数没有执行条件,
3-2=Text.Combine (List.Transform({1..6,{1..6,{1..6,{1..6}}}} ,....))这个Text.Combine 函数没有执行条件,
3-3=Text.Combine (List.Transform({1..6,{1..6,{1..6}}} ,....))这个Text.Combine 函数没有执行条件,
3-4=Text.Combine (List.Transform({1..6,{1..6}} ,....))这个Text.Combine 函数没有执行条件,
3-5=Text.Combine (List.Transform({1..6},....))二个函数完全执行,结果是"123456"
最后我们发现 源 =Text.Combine (List.Transform( {{1..3},{2..6,{1..3,{1..3,{2..6}}}},{4..9,{1..6,{1..6,{1..6,{1..6}}}}}},....))这个
Text.Combine (只有当所有条件满足时才会执行,所以是最后执行的)
file
结果:1232345612312323456456789123456123456123456123456
file

= let a = "100010000100000" ,fx=(x) =>if Text.Contains(x,"00") then  @fx(Text.Replace(x,"00","0") ) else x  in fx(a)
= let fx=(x)=>if x={} then {} else [a= List.Accumulate(x,0,(s ,y)=>if s>y then s else y),b= {a}&@fx(List.Difference(x,{a}))][b] in fx({5,6,8,100,9,8,7,7,5})

file

看完后你发现@fx()太厉害了,