···638 # Input list
639 list: sublist count (length list) list;
6400000000000000000000000000000000000641 /* Return a list consisting of at most `count` elements of `list`,
642 starting at index `start`.
643
···638 # Input list
639 list: sublist count (length list) list;
640641+ /* Whether the first list is a prefix of the second list.
642+643+ Type: hasPrefix :: [a] -> [a] -> bool
644+645+ Example:
646+ hasPrefix [ 1 2 ] [ 1 2 3 4 ]
647+ => true
648+ hasPrefix [ 0 1 ] [ 1 2 3 4 ]
649+ => false
650+ */
651+ hasPrefix =
652+ list1:
653+ list2:
654+ take (length list1) list2 == list1;
655+656+ /* Remove the first list as a prefix from the second list.
657+ Error if the first list isn't a prefix of the second list.
658+659+ Type: removePrefix :: [a] -> [a] -> [a]
660+661+ Example:
662+ removePrefix [ 1 2 ] [ 1 2 3 4 ]
663+ => [ 3 4 ]
664+ removePrefix [ 0 1 ] [ 1 2 3 4 ]
665+ => <error>
666+ */
667+ removePrefix =
668+ list1:
669+ list2:
670+ if hasPrefix list1 list2 then
671+ drop (length list1) list2
672+ else
673+ throw "lib.lists.removePrefix: First argument is not a list prefix of the second argument";
674+675 /* Return a list consisting of at most `count` elements of `list`,
676 starting at index `start`.
677