Change the list of lists

I want to make a function that accepts int list listand returns int list list, but each time the list is returned. Example:

[[1;2;3];[4;5;6]] -> [[6;5;4];[3;2;1]]

The function that I have encountered so far is missing, which I do not see and returns:

 [[4;5;6];[6;5;4]]

It looks like this:

let revrev lstOfLst = 
    let revrevInner lst = 
        List.fold (fun rst x -> x::rst) [] lst
    List.fold (fun rst x -> x::[(revrevInner x)]) [] lstOfLst 
+4
source share
2 answers

After reading my function again, I noticed that I was not using the first in the first shift. The function should look like this:

let revrev lstOfLst = 
    let revrevInner lst = 
        List.fold (fun rst x -> x::rst) [] lst
    List.fold (fun rst x -> (revrevInner x)::rst) [] lstOfLst 
+4
source
let revRev lstOfLst =
    List.fold (fun s x -> (List.rev x) :: s) [] lstOfLst
+1
source

Source: https://habr.com/ru/post/1688291/


All Articles