Paste: typed containers
Author: | j |
Mode: | factor |
Date: | Tue, 22 Nov 2011 00:08:19 |
Plain Text |
USING: typed.containers ;
IN: typed.containers.tests
DEFER: sequence-protocol
<< \ sequence-protocol sequence { "T" } {
{ nth-unsafe ( n elt -- T ) }
{ set-nth-unsafe ( T n elt -- ) }
} define-typed-protocol >>
DEFER: fixnum-sequence
<< \ fixnum-sequence \ sequence-protocol { fixnum } create-typed-instance >>
: test-fixnum-sequence
{ 1 2 3 } fixnum-sequence wrap-typed-instance-unsafe ; inline
{ 1 } [ test-fixnum-sequence first ] unit-test
{ 2 } [ test-fixnum-sequence first 1 + >fixnum ] unit-test
{ t } [ [ test-fixnum-sequence first 1 + >fixnum ] \ + inlined? ] unit-test
{ 4 } [ 4 test-fixnum-sequence [ set-first ] [ first ] bi ] unit-test
[ 4.0 test-fixnum-sequence [ set-first ] [ first ] bi ] [ type-error? ] must-fail-with
New Annotation