 M: forward-cursor new-sequence-cursor
     new-growable-cursor ; inline
 
-: -into-sequence- ( begin end quot exemplar -- begin' end' quot' result )
-    swap [ [ 2dup ] dip new-sequence-cursor ] dip swap [ swap -pipe- ] dip ; inline
-
-: -into-growable- ( begin end quot exemplar -- begin' end' quot' result )
-    swap [ [ 2dup ] dip new-growable-cursor ] dip swap [ swap -pipe- ] dip ; inline
-
-!
-! map
-!
-
-: -map- ( quot -- quot' )
-    '[ _ keep set-cursor-value-unsafe ] ; inline
-
-: -map ( ... begin end quot: ( ... cursor -- ... value ) -- ... )
-    -map- -each ; inline
+: -into-sequence- ( begin end quot exemplar -- begin' end' quot' cursor result )
+    [ 2over ] dip new-sequence-cursor ; inline
+
+: -into-growable- ( begin end quot exemplar -- begin' end' quot' cursor result )
+    [ 2over ] dip new-sequence-cursor ; inline
+
+!
+! map combinators
+!
 
 ! XXX generalize exemplar
 : -map-as ( ... begin end quot: ( ... cursor -- ... value ) exemplar -- ... newseq )
     [ -into-sequence- [ -map ] dip ] keep like ; inline
 
 : map! ( ... container quot: ( ... x -- ... newx ) -- ... container )
-    [ container- -map ] keep ; inline
+    [ in- -out ] keep ; inline
 : map-as ( ... container quot: ( ... x -- ... newx ) exemplar -- ... newseq )
-    [ container- ] dip -map-as ; inline
+    [ in- ] dip -map-as ; inline
 : map ( ... container quot: ( ... x -- ... newx ) -- ... newcontainer )
     over map-as ; inline
 

M: end-of-stream cursor-stream-ended? drop t ; inline

!
! basic iterator
!

: -each ( ... begin end quot: ( ... cursor -- ... ) -- ... )
    [ '[ dup _ cursor>= ] ]
    [ '[ _ keep inc-cursor ] ] bi* until drop ; inline

!
! numeric cursors

M: sequence-cursor set-cursor-value [ n>> ] [ seq>> ] bi set-nth ; inline

!
! map cursor
!

TUPLE: map-cursor
    { from read-only }
    { to read-only } ;
C: <map-cursor> map-cursor

INSTANCE: map-cursor forward-cursor

M: map-cursor cursor-compatible? [ from>> ] bi@ cursor-compatible? ; inline
M: map-cursor cursor-valid? [ from>> ] [ to>> ] bi [ cursor-valid? ] both? ; inline
M: map-cursor cursor= [ from>> ] bi@ cursor= ; inline
M: map-cursor inc-cursor [ from>> inc-cursor ] [ to>> inc-cursor ] bi <map-cursor> ; inline

INSTANCE: map-cursor output-cursor

M: map-cursor set-cursor-value-unsafe to>> set-cursor-value-unsafe ; inline
M: map-cursor set-cursor-value        to>> set-cursor-value        ; inline

: -map- ( begin end quot to -- begin' end' quot' )
    swap [ '[ _ <map-cursor> ] bi@ ] dip '[ from>> @ ] ; inline

: -map ( begin end quot to -- begin' end' quot' )
    -map- -out ; inline

!
! pusher cursor
