         [ [ 2 * 1 + ] dip nth-unsafe ] curry
     ] keep map-integers ;
 
-: compact ( seq quot elt -- seq' )
+: compact ( ... seq quot: ( ... elt -- ... ? ) elt -- ... seq' )
     [ split-when harvest ] dip join ; inline
 
-: collapse ( seq quot elt -- seq' )
+: collapse ( ... seq quot: ( ... elt -- ... ? ) elt -- ... seq' )
     [ split-when ] dip
     [ [ harvest ] dip join ]
     [ [ first empty? ] dip [ prepend ] curry when ]

    [ dup empty? ] swap until drop ; inline

: arg-max ( seq -- n )
    dup length iota zip [ first-unsafe ] supremum-by second ;

: arg-min ( seq -- n )
    dup length iota zip [ first-unsafe ] infimum-by second ;

: arg-where ( ... seq quot: ( ... elt -- ... ? ) -- ... indices )
    [ dup length iota zip ] dip
    [ first-unsafe ] prepose filter values ; inline

: arg-sort ( seq -- indices )
    dup length iota zip sort-keys values ;

USING: accessors arrays assocs fry grouping growable kernel
locals make math math.order math.ranges sequences
sequences.deep sequences.private sorting splitting vectors ;
FROM: sequences => change-nth ;
IN: sequences.extras

