assoc
Factor documentation > Factor handbook > The language > Collections > Associative mapping operations > Associative mapping protocol
Next:assoc? ( object -- ? )


Vocabulary
assocs

Class description
A mixin class whose instances are associative mappings. Custom implementations of the assoc protocol should be declared as instances of this mixin for all assoc functionality to work correctly:
INSTANCE: avl-tree assoc


Definition
USING: biassocs cache classes.struct.prettyprint env hashtables
hashtables.wrapped linked-assocs mirrors pairs quadtrees redis
sequences sequences.n-based tokyo.abstractdb tokyo.remotedb
trees vlists xml.data xmode.keyword-map ;

IN: assocs

MIXIN: assoc
INSTANCE: sequence assoc
INSTANCE: enum assoc
INSTANCE: hashtable assoc
INSTANCE: wrapped-hashtable assoc
INSTANCE: biassoc assoc
INSTANCE: mirror assoc
INSTANCE: struct-mirror assoc
INSTANCE: linked-assoc assoc
INSTANCE: attrs assoc
INSTANCE: cache-assoc assoc
INSTANCE: keyword-map assoc
INSTANCE: valist assoc
INSTANCE: env assoc
INSTANCE: pair assoc
INSTANCE: quadtree assoc
INSTANCE: tree assoc
INSTANCE: redis assoc
INSTANCE: n-based-assoc assoc
INSTANCE: tokyo-abstractdb assoc
INSTANCE: tokyo-remotedb assoc


Methods
USING: accessors assocs kernel mongodb.msg sequences ;

M: assoc <mdb-insert-msg>
[ mdb-insert-msg new ] 2dip [ >>collection ] dip
[ V{ } clone ] dip suffix! >>objects OP_Insert >>opcode ;


USING: accessors assocs http http.client.post-data.private
kernel ;

M: assoc >post-data
"application/x-www-form-urlencoded" <post-data> swap
>>params ;


USING: assocs formatting kernel sequences txon txon.private ;

M: assoc >txon
>alist
[ first2 [ encode-value ] [ >txon ] bi* "%s:`%s`" sprintf ]
map "\n" join ;


USING: assocs inspector inspector.private kernel namespaces
sequences ;

M: assoc add-numbers
+number-rows+ get [ [ prefix ] map-index ] when ;


USING: assocs assocs.private kernel ;

M: assoc assoc-clone-like
[ dup assoc-size ] dip new-assoc
[ [ set-at ] with-assoc assoc-each ] keep ; inline


USING: assocs kernel ;

M: assoc assoc-like drop ; inline


USING: assocs inspector.private ;

M: assoc fix-slot-names >alist ;


USING: assocs benchmark.dispatch3 kernel ;

M: assoc g drop "assoc" ;


USING: assocs kernel ;

M: assoc keys [ drop ] { } assoc>map ;


USING: assocs hashtables kernel ;

M: assoc new-assoc drop <hashtable> ; inline


USING: assocs kernel persistent.assocs ;

M: assoc new-at clone [ set-at ] keep ;


USING: assocs kernel persistent.assocs ;

M: assoc pluck-at clone [ delete-at ] keep ;


USING: assocs random ;

M: assoc random >alist random ;


USING: assocs smalltalk.selectors ;

M: assoc selector-at: at ;


USING: assocs kernel smalltalk.selectors ;

M: assoc selector-at:put: [ swapd set-at ] keep ;


USING: accessors assocs classes kernel make math.parser summary
;

M: assoc summary
[
dup class-of name>> % " with " % assoc-size #
" entries" %
] "" make ;


USING: assocs kernel ;

M: assoc value-at* swap [ = nip ] curry assoc-find nip ;


USING: assocs kernel ;

M: assoc values [ nip ] { } assoc>map ;