Paste: group-by
Author: | mrjbq7 |
Mode: | factor |
Date: | Sat, 9 Apr 2011 17:21:03 |
Plain Text |
: (sequence>assoc) ( seq quot: ( elt -- value key ) quot: ( value key assoc -- ) assoc -- assoc )
[ swap curry compose each ] keep ; inline
: sequence>assoc ( seq quot: ( elt -- value key ) quot: ( value key assoc -- ) exemplar -- assoc )
clone (sequence>assoc) ; inline
: sequence>hashtable ( seq quot: ( elt -- value key ) quot: ( value key hashtable -- ) -- hashtable )
H{ } sequence>assoc ; inline
: group-by ( seq quot: ( elt -- value key ) -- hashtable )
[ push-at ] sequence>hashtable ; inline
: group-by-key ( seq quot: ( elt -- key ) -- hashtable )
[ dup ] prepose group-by ; inline
: group-by-value ( seq quot: ( elt -- value ) -- hashtable )
[ dup ] compose group-by ; inline
New Annotation