Hi Factor list

A couple of times recently I've needed a way to map keys to multiple
values and have implemented this as a hash of sequences. I was wondering
if there was any support in the factor libraries to help with doing
this, or a better way?

If not, do you think it would be worth having an assoc wrapper that
implements set-at thus:

: set-at ( value key assoc -- )
   underlying-assoc>>
   swapd [ [ swap suffix ] [ 1array ] if* ] with change-at ;

.. which would then allow map>assoc to work.

Or would it be better to have separate words - e.g.  map>assoc-append
and append-at?

: append-at ( value key assoc -- )
   swapd [ [ swap suffix ] [ 1array ] if* ] with change-at ;

: map>assoc-append ( seq quot assoc -- )
   [ swapd append-at ] curry compose each ;

{ 1 2 3 2 4 5 6 } [ 20000 random ] H{ } clone [ map>assoc-append ] keep .
H{
     { 1 { 6544 } }
     { 2 { 19297 4140 } }
     { 3 { 16399 } }
     { 4 { 13828 } }
     { 5 { 10744 } }
     { 6 { 18577 } }
}

Cheers,

Phil




-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to