janestreet / base

Standard library for OCaml
MIT License
860 stars 125 forks source link

Functional Array.rev? #108

Closed dieggsy closed 3 years ago

dieggsy commented 3 years ago

I'm totally new to OCaml, but I think it's really neat that the Array module supports functional operations on arrays. One thing I sort of missed which I think can be quite useful is a functional reverse (in the style of List.rev), which I've simply defined below in terms of Array.copy and Array.rev_inplace.

  let array_rev array =
    let copy = Array.copy array in
    Array.rev_inplace copy;
    copy

Is there good reason something like this shouldn't be in the Array module?

seliopou commented 3 years ago

Sure, we can add that.

aalekseyev commented 3 years ago

Added in 74e7608

seliopou commented 3 years ago

Closing, as the change has been merged.