fix ?at, if-at and add unit tests
parent
ab56eb0e48
commit
16342a8a40
|
@ -1,4 +1,17 @@
|
|||
USING: kernel tools.test sequences vectors assocs.lib ;
|
||||
IN: assocs.lib.tests
|
||||
USING: assocs.lib tools.test vectors ;
|
||||
|
||||
{ 1 1 } [ [ ?push ] histogram ] must-infer-as
|
||||
|
||||
! substitute
|
||||
[ { 2 } ] [ { 1 } H{ { 1 2 } } [ ?at drop ] curry map ] unit-test
|
||||
[ { 3 } ] [ { 3 } H{ { 1 2 } } [ ?at drop ] curry map ] unit-test
|
||||
|
||||
[ 2 ] [ 1 H{ { 1 2 } } [ ] [ ] if-at ] unit-test
|
||||
[ 3 ] [ 3 H{ { 1 2 } } [ ] [ ] if-at ] unit-test
|
||||
|
||||
[ "hi" ] [ 1 H{ { 1 2 } } [ drop "hi" ] when-at ] unit-test
|
||||
[ 3 ] [ 3 H{ { 1 2 } } [ drop "hi" ] when-at ] unit-test
|
||||
[ 2 ] [ 1 H{ { 1 2 } } [ drop "hi" ] unless-at ] unit-test
|
||||
[ "hi" ] [ 3 H{ { 1 2 } } [ drop "hi" ] unless-at ] unit-test
|
||||
|
||||
|
|
|
@ -38,11 +38,11 @@ IN: assocs.lib
|
|||
swap [ change-at ] 2curry assoc-each
|
||||
] keep ; inline
|
||||
|
||||
: ?at ( obj1 assoc -- obj1/obj2 )
|
||||
dupd at* [ nip ] [ drop ] if ;
|
||||
: ?at ( obj assoc -- value/obj ? )
|
||||
dupd at* [ [ nip ] [ drop ] if ] keep ;
|
||||
|
||||
: if-at ( obj assoc quot1 quot2 -- )
|
||||
[ ?at dup ] 2dip if ; inline
|
||||
[ ?at ] 2dip if ; inline
|
||||
|
||||
: when-at ( obj assoc quot -- ) [ ] if-at ; inline
|
||||
|
||||
|
|
Loading…
Reference in New Issue