I didn't really test how fast this implementation is (feel free to do so and modify if you know something better) but It is as fast as the regular FlattenAt and it handles all* cases of Span.
Clear[flattenSpan, list]
flattenSpan[list_, span_]:=Module[{range},
range = span /. All-> Length@list
/.{Span[a_,b_] /;b<a :>Table[{i}, {i,a,Length@list+b}],
Span[a_,b_] :> Table[{i}, {i, a, b}],
Span[a_,b_, c_] /; b<a :>Table[{i}, {i, a,Length@list+ b, c}],
Span[a_,b_, c_] :>Table[{i}, {i, a, b, c}]};
FlattenAt[list, range]
]
Examples: for list = {{a}, {b,c}, {d, e}, {f}, {g, h,i}, {j}, {k, l}}
flattenSpan[list, 2;;] (* flattens all elements starting from the second*)
(* {{a},b,c,d,e,f,g,h,i,j,k,l} *)
flattenSpan[list, ;;;;2] (* flattens every second element*)
(* {a,{b,c},d,e,{f},g,h,i,{j},k,l} *)
flattenSpan[list, 1;;4;;2] (* flattens every second element between 1 and 4*)
(* {a,{b,c},d,e,{f},{g,h,i},{j},{k,l}} *)
flattenSpan[list, ;;] (* flattens all elements*)
(* {a,b,c,d,e,f,g,h,i,j,k,l} *)
negative indices work as well with one little caveat*: to flatten the last 4 entries in the list one has to use -4;;-1 whereas in MapAt -4;; would suffice.
flattenSpan[list, -4;;-1] (* flattens the last 4 elements*)
(* {{a},{b,c},{d,e},f,g,h,i,j,k,l} *)
Fixed the issue mentioned in the comment
flattenSpan[list, 1;;-2] (*flattens all elements from 1 to the second-last*)
(* {a,b,c,d,e,f,g,h,i,{j},{k,l}} *)
MapAt[Apply@Sequence, {a, {b, c}, {d, e}, f}, 2 ;; 3]? – Leonid Shifrin Jan 07 '16 at 16:52FlattenAtfunction from my answer seems to be a bit faster though, especially for a long list of positions. – Sascha Jan 07 '16 at 19:43Applywill not work inside a held expression so this is not equivalent toFlattenAt. – Mr.Wizard Jan 29 '16 at 01:03FlattenAt, so wasn't aware that it works inside held expressions - which is of course natural to expect once we think about it (in fact didn't even think in that direction, since typically my uses of held code andFlattendon't overlap). But that's a good point. I will make a note in my answer. Thanks for spotting this. – Leonid Shifrin Jan 29 '16 at 01:16