: substituter ( assoc -- quot )
[ ?at drop ] curry ; inline
-: with-assoc ( assoc quot: ( ..a value key assoc -- ..b ) -- quot: ( ..a key value -- ..b ) )
- curry [ swap ] prepose ; inline
-
PRIVATE>
: assoc-find ( ... assoc quot: ( ... key value -- ... ? ) -- ... key value ? )
: last-index-from ( obj i seq -- n )
rot [ = ] curry find-last-from drop ;
+: with-assoc ( assoc quot: ( ..a value key assoc -- ..b ) -- quot: ( ..a key value -- ..b ) )
+ curry [ swap ] prepose ; inline
+
: indices ( obj seq -- indices )
- swap [ = ] curry [ swap ] prepose V{ } clone [
+ swap [ = ] with-assoc V{ } clone [
[ push ] curry [ [ drop ] if ] curry compose each-index
] keep ;
: shorter? ( seq1 seq2 -- ? ) 2length < ; inline
: longer? ( seq1 seq2 -- ? ) 2length > ; inline
-: shorter ( seq1 seq2 -- seq ) [ 2length <= ] 2keep ? ; inline
-: longer ( seq1 seq2 -- seq ) [ 2length >= ] 2keep ? ; inline
+: shorter ( seq1 seq2 -- seq ) [ 2length <= ] most ; inline
+: longer ( seq1 seq2 -- seq ) [ 2length >= ] most ; inline
: head? ( seq begin -- ? )
2dup shorter? [
: supremum ( seq -- elt ) [ ] [ max ] map-reduce ;
: map-sum ( ... seq quot: ( ... elt -- ... n ) -- ... n )
- [ 0 ] 2dip [ dip + ] curry [ swap ] prepose each ; inline
+ [ 0 ] 2dip [ dip + ] with-assoc each ; inline
: count ( ... seq quot: ( ... elt -- ... ? ) -- ... n )
[ 1 0 ? ] compose map-sum ; inline
[ (reverse) ] [ like ] bi* ;
: map-product ( ... seq quot: ( ... elt -- ... n ) -- ... n )
- [ 1 ] 2dip [ dip * ] curry [ swap ] prepose each ; inline
+ [ 1 ] 2dip [ dip * ] with-assoc each ; inline
: insert-nth! ( elt n seq -- )
[ length ] keep ensure swap pick (a..b]