: 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 [ = ] with-assoc V{ } clone [
+ swap [ = ] curry [ swap ] prepose V{ } clone [
[ push ] curry [ [ drop ] if ] curry compose each-index
] keep ;
: supremum ( seq -- elt ) [ ] [ max ] map-reduce ;
: map-sum ( ... seq quot: ( ... elt -- ... n ) -- ... n )
- [ 0 ] 2dip [ dip + ] with-assoc each ; inline
+ [ 0 ] 2dip [ dip + ] curry [ swap ] prepose each ; inline
: count ( ... seq quot: ( ... elt -- ... ? ) -- ... n )
[ 1 0 ? ] compose map-sum ; inline