I'm trying to write a function using List.foldBack that'll split a list of integers into a tuple containing two lists: One containing the odds and the other the evens of the original list. Example:
Given the list myList = [1;4;2;6;5;3;10], the function should return the tuple ([4;2;6;10], [1;5;3]).
I have found plenty of solutions for splitting lists into sublists by their indices, however as explained I need to split the list by element value, not index.
So I figured I would write a function using List.foldBack that would split by index and then rewrite it to split by value, but have yet to be successful ... here is what I've arrived at so far:
let oddEvenSplit (listToSplit:int list) =
List.foldBack (fun x (even, odd) -> x::odd, even) listToSplit ([], [])
As you might've guessed, running myList through my function returns ([1;2;5;10], [4;6;3]).
I am restricted to using List.-fold, foldBack, find, filter, map, and map2, but would prefer to see a solution using only foldBack, if possible.