···638638 # Input list
639639 list: sublist count (length list) list;
640640641641+ /* Whether the first list is a prefix of the second list.
642642+643643+ Type: hasPrefix :: [a] -> [a] -> bool
644644+645645+ Example:
646646+ hasPrefix [ 1 2 ] [ 1 2 3 4 ]
647647+ => true
648648+ hasPrefix [ 0 1 ] [ 1 2 3 4 ]
649649+ => false
650650+ */
651651+ hasPrefix =
652652+ list1:
653653+ list2:
654654+ take (length list1) list2 == list1;
655655+656656+ /* Remove the first list as a prefix from the second list.
657657+ Error if the first list isn't a prefix of the second list.
658658+659659+ Type: removePrefix :: [a] -> [a] -> [a]
660660+661661+ Example:
662662+ removePrefix [ 1 2 ] [ 1 2 3 4 ]
663663+ => [ 3 4 ]
664664+ removePrefix [ 0 1 ] [ 1 2 3 4 ]
665665+ => <error>
666666+ */
667667+ removePrefix =
668668+ list1:
669669+ list2:
670670+ if hasPrefix list1 list2 then
671671+ drop (length list1) list2
672672+ else
673673+ throw "lib.lists.removePrefix: First argument is not a list prefix of the second argument";
674674+641675 /* Return a list consisting of at most `count` elements of `list`,
642676 starting at index `start`.
643677