assoc - Factor Documentation (original) (raw)
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:
USING: assocs kernel yaml.private ;
M: assoc (deref-aliases)
[ [ (deref-aliases) ] bi-curry@ bi ] withd assoc-map! ;
USING: assocs kernel yaml.private ;
M: assoc (replace-aliases)
swap [ swap ?replace-aliases ] curry [ bi@ ] curry assoc-map
;
USING: assocs kernel yaml.private ;
M: assoc (replace-anchors)
swap [ swap ?replace-anchors ] curry [ bi@ ] curry assoc-map
;
USING: accessors assocs kernel mongodb.msg sequences ;
M: assoc
[ mdb-insert-msg new ] 2dip [ >>collection ] dip
[ V{ } clone ] dip suffix! >>objects OP_Insert >>opcode ;
USING: assocs bencode kernel sequences ;
M: assoc >bencode
[ [ >bencode ] bi@ append ] { } assoc>map
concat "d" "e" surround ;
USING: accessors assocs http http.client.post-data kernel ;
M: assoc >post-data
"application/x-www-form-urlencoded" swap
>>params ;
USING: assocs formatting kernel sequences splitting txon
txon.private ;
M: assoc >txon
>alist
[ first2 [ encode-value ] [ >txon ] bi* "%s:`%s`" sprintf ]
map join-lines ;
USING: assocs inspector inspector.private kernel namespaces
sequences ;
M: assoc add-numbers
+number-rows+ get [ [ prefix ] map-index ] when ;
USING: assocs kernel namespaces yaml yaml.config yaml.private ;
M: assoc apply-merge-keys
[ [ ?apply-merge-keys ] bi-curry@ bi ] withd assoc-map!
merge get [ ?apply-merge-key ] when value get
[ ?apply-default-key ] when ;
M: assoc assoc-clone-like
over [ assoc-size ] [ new-assoc ] [ assoc-union! ] tri* ;
inline
M: assoc assoc-like drop ; inline
M: assoc clone-like assoc-clone-like ;
USING: assocs assocs.extras kernel ;
M: assoc delete-value-at
[ value-at* ] 1check [ delete-at ] [ 2drop ] if ;
USING: assocs combinators.extras kernel namespaces yaml.config
yaml.ffi yaml.private ;
M: assoc emit-value
[ drop YAML_MAP_TAG implicit-tags get emit-assoc-start ]
[ nip emit-assoc-body ] [ 2drop emit-assoc-end ] 4tri ;
USING: assocs inspector.private ;
M: assoc fix-slot-names >alist ;
USING: assocs benchmark.dispatch3 kernel ;
M: assoc keys [ drop ] { } assoc>map ;
USING: assocs kernel yaml.private ;
M: assoc merge-value over assoc-diff assoc-union! ;
USING: assocs hashtables kernel ;
M: assoc new-assoc drop ; 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 io json.prettyprint.private kernel namespaces
sequences ;
M: assoc pprint-json*
dup assoc-empty?
[ drop "{ }" write ] [
"{" print indent-level inc >alist
[ "," print ] [
first2
[ write-spaces pprint-json* ": " write ]
[ pprint-json* ] bi*
] interleave nl indent-level dec write-spaces "}" write
] if ;
M: assoc random* [ >alist ] dip random* ;
M: assoc remove-all clear-assoc ;
USING: assocs smalltalk.selectors ;
USING: assocs kernel smalltalk.selectors ;
M: assoc selector-at:put: [ swapd set-at ] keep ;
USING: assocs json json.private ;
M: assoc stream-write-json write-json-assoc ;
USING: assocs kernel summary ;
M: assoc tuple-summary
dup assoc-size "entries" container-summary ;
USING: assocs kernel sequences ;
M: assoc unzip
dup assoc-empty? [ drop { } { } ] [ >alist flip first2 ] if
;
M: assoc value-at* swap [ = nip ] curry assoc-find nip ;
M: assoc values [ nip ] { } assoc>map ;
USING: assocs cbor cbor.private kernel sequences ;
M: assoc write-cbor
dup length 5 write-integer [ [ write-cbor ] bi@ ] assoc-each
;
USING: assocs kernel msgpack msgpack.private ;
M: assoc write-msgpack
dup assoc-size write-map-header
[ [ write-msgpack ] bi@ ] assoc-each ;