sequences.extras: faster minimum/maximum.

db4
John Benediktsson 2012-04-16 15:09:44 -07:00
parent ba663e2fd5
commit 17d9b1ba40
1 changed files with 2 additions and 4 deletions

View File

@ -30,12 +30,10 @@ IN: sequences.extras
[ bi@ [ min ] keep eq? not ] curry most ; inline [ bi@ [ min ] keep eq? not ] curry most ; inline
: maximum ( seq quot: ( ... elt -- ... x ) -- elt ) : maximum ( seq quot: ( ... elt -- ... x ) -- elt )
[ keep 2array ] curry [ dup ?first ] dip [ max-by ] curry reduce ; inline
[ [ first ] max-by ] map-reduce second ; inline
: minimum ( seq quot: ( ... elt -- ... x ) -- elt ) : minimum ( seq quot: ( ... elt -- ... x ) -- elt )
[ keep 2array ] curry [ dup ?first ] dip [ min-by ] curry reduce ; inline
[ [ first ] min-by ] map-reduce second ; inline
: all-subseqs ( seq -- seqs ) : all-subseqs ( seq -- seqs )
dup length [1,b] [ <clumps> ] with map concat ; dup length [1,b] [ <clumps> ] with map concat ;