   (--drop-while (funcall pred it) list))
 
 (defun -split-at (n list)
-  "Returns a list of ((-take N LIST) (-drop N LIST))"
-  (list (-take n list)
-        (-drop n list)))
-
-(defmacro --split-with (form list)
+  "Returns a list of ((-take N LIST) (-drop N LIST)), in no more than one pass through the list."
+  (let (result)
+    (--dotimes n
+      (when list
+        (!cons (car list) result)
+        (!cdr list)))
+    (list (nreverse result) list)))
+
+(defun -insert-at (n x list)
+  "Returns a list with X inserted into LIST at position N."
+  (let ((split-list (-split-at n list)))
+    (nconc (car split-list) (cons x (cadr split-list)))))
+
+(defmacro --split-with (pred list)
   "Anaphoric form of `-split-with'."
-  `(list (--take-while ,form ,list)
-         (--drop-while ,form ,list)))
+  (let ((l (make-symbol "list"))
+        (r (make-symbol "result"))
+        (c (make-symbol "continue")))
+    `(let ((,l ,list)
+           (,r nil)
+           (,c t))
+       (while (and ,l ,c)
+         (let ((it (car ,l)))
+           (if (not ,pred)
+               (setq ,c nil)
+             (!cons it ,r)
+             (!cdr ,l))))
+       (list (nreverse ,r) ,l))))
 
 (defun -split-with (pred list)
-  "Returns a list of ((-take-while PRED LIST) (-drop-while PRED LIST))"
+  "Returns a list of ((-take-while PRED LIST) (-drop-while PRED LIST)), in no more than one pass through the list."
   (--split-with (funcall pred it) list))
 
 (defmacro --separate (form list)

           (nreverse ,r))))))

(defun -partition-by (fn list)
  "Applies FN to each value in LIST, splitting it each time FN returns a new value."
  (--partition-by (funcall fn it) list))

(defmacro --group-by (form list)
  "Anaphoric form of `-group-by'."

;; Copyright (C) 2012 Magnar Sveen

;; Author: Magnar Sveen <magnars@gmail.com>
;; Version: 20130424.943
;; X-Original-Version: 1.2.0
;; Keywords: lists

;; This program is free software; you can redistribute it and/or modify
