linked-assocs: fix assoc-map on linked-assocs.

db4
John Benediktsson 2014-04-27 15:03:35 -07:00
parent 64bb56665b
commit cb9b04c153
2 changed files with 23 additions and 5 deletions

View File

@ -1,6 +1,7 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences assocs tools.test linked-assocs math ;
USING: accessors assocs kernel linked-assocs math sequences
tools.test ;
IN: linked-assocs.test
{ { 1 2 3 } } [
@ -63,3 +64,13 @@ IN: linked-assocs.test
3 "cx" pick set-at
>alist
] unit-test
{ t V{ { 1 20 } { 3 40 } { 5 60 } } } [
{ { 1 2 } { 3 4 } { 5 6 } } >linked-hash
[ 10 * ] assoc-map [ linked-assoc? ] [ >alist ] bi
] unit-test
{ V{ { 1 2 } { 3 4 } { 5 6 } } } [
{ { 1 2 } { 3 4 } { 5 6 } }
{ } <linked-assoc> assoc-like >alist
] unit-test

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov, James Cash.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs deques dlists fry kernel
USING: accessors arrays assocs classes deques dlists fry kernel
sequences sequences.private ;
IN: linked-assocs
@ -45,8 +45,15 @@ M: linked-assoc >alist
M: linked-assoc clear-assoc
[ assoc>> clear-assoc ] [ dlist>> clear-deque ] bi ;
M: linked-assoc clone
[ assoc>> clone ] [ dlist>> clone ] bi
linked-assoc boa ;
M: linked-assoc clone
[ assoc>> clone ] [ dlist>> clone ] bi linked-assoc boa ;
INSTANCE: linked-assoc assoc
: >linked-hash ( assoc -- assoc )
[ <linked-hash> ] dip assoc-union! ;
M: linked-assoc assoc-like
over linked-assoc?
[ 2dup [ assoc>> ] bi@ class-of instance? ] [ f ] if
[ drop ] [ assoc>> <linked-assoc> swap assoc-union! ] if ;