I have a list of items looking something like this:
let myList = [ "One"; "Two"; "Three and Four"; "Five"; "and Six"; "Seven and"; "Nine and Ten and Eleven" ]
I need to split every item containing the word and
into separate items and re-insert them into the list, while keeping the order. Is there any elegant and efficient way how to do this? Currently I am using a loop and mutable list for aggregation:
let mutable result = []
for item in myList do
let split = item.Split("and", StringSplitOptions.RemoveEmptyEntries)
for subItem in split do
result <- subItem::result
List.rev result
I have a suspicion that there is a better way to do this (more functional, less C#-y), but I cannot find out how to do it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…