janestreet / base

Standard library for OCaml
MIT License
848 stars 124 forks source link

make List.take return physical identity for n = length #153

Closed mroch closed 1 year ago

mroch commented 1 year ago

I'd like List.take t n to return t when n >= List.length t. then I can tell if any were dropped if t != t'.

right now, it does when n > List.length t:

https://github.com/janestreet/base/blob/041bbbba50cf25a35c14e7c042ba4fe33521851e/src/list.ml#L1430

but it unnecessarily clones when the length is exactly n.

it'd be great to mention this in the docs so it's part of the public API :)

dkalinichenko-js commented 1 year ago

Done!