Version française
Home     About     Download     Resources     Contact us    
Browse thread
Preferred Way to Split a List
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nathaniel Gray <n8gray@g...>
Subject: Re: [Caml-list] Preferred Way to Split a List
On Oct 30, 2007 6:18 AM, Robert Fischer <robert@fischerventure.com> wrote:
>
> > Do you need to preserve ordering in the sublists?
> >
> Yes.
> > Do they need to be roughly equivalent lengths?
> No -- the head list will probably be shorter than the tail list.

Hmm...

let fast_list_splitter = function
   | h :: t -> [h], t
   | [] -> [], []  (* Or maybe raise an exception? *)

Or if you're really shooting for speed:

let golly_it's_fast_list_splitter lst = [], lst

I win.  Seriously, you must have *some* further constraints!

Cheers,
-n8

-- 
>>>-- Nathaniel Gray -- Caltech Computer Science ------>
>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->