I have a list and would like to return each item from it individually. Basically, how to pop out of the stack. For instance:
let rnd = new System.Random() let rnds = List.init 10 (fun _ -> rnd.Next(100)) List.iter (fun x -> printfn "%A"x ) rnds
However, instead of repeating, I would really like to return each integer one by one until the list becomes empty. So basically something like:
List.head(rnds) List.head(List.tail(rnds)) List.head(List.tail(List.tail(rnds))) List.head(List.tail(List.tail(List.tail(List.tail(rnds)))))
Unfortunately, my attempts at a recursive solution or even better to use something bend or scan were unsuccessful. For example, this simply returns a list (same as a map).
let pop3 (rnds:int list) = let rec pop3' rnds acc = match rnds with | head :: tail -> List.tail(tail) | [] -> acc pop3' [] rnds
source share