From bbd00d2012833c6419a62f6490cbef3e896b1e11 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 9 Oct 2015 12:10:47 -0400 Subject: utils: Add split procedure. * guix/utils.scm (split): New procedure. * tests/utils.scm: Add tests. --- guix/utils.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'guix/utils.scm') diff --git a/guix/utils.scm b/guix/utils.scm index 1d4b2ff9b0..0802a1b67a 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2013, 2014, 2015 Mark H Weaver ;;; Copyright © 2014 Eric Bavier ;;; Copyright © 2014 Ian Denhardt +;;; Copyright © 2015 David Thompson ;;; ;;; This file is part of GNU Guix. ;;; @@ -79,6 +80,7 @@ fold2 fold-tree fold-tree-leaves + split filtered-port compressed-port @@ -684,6 +686,23 @@ are connected to NODE in the tree, or '() or #f if NODE is a leaf node." (else result))) init children roots)) +(define (split lst e) + "Return two values, a list containing the elements of the list LST that +appear before the first occurence of the object E and a list containing the +elements after E." + (define (same? x) + (equal? e x)) + + (let loop ((rest lst) + (acc '())) + (match rest + (() + (values lst '())) + (((? same?) . tail) + (values (reverse acc) tail)) + ((head . tail) + (loop tail (cons head acc)))))) + ;;; ;;; Source location. -- cgit v1.2.3