splitting.monotonic: Don't throw away the last result. Fixes #462.

db4
Doug Coleman 2011-12-27 11:43:32 -06:00
parent b094d4d0ec
commit 6fdf24d5b4
2 changed files with 26 additions and 5 deletions

View File

@ -53,3 +53,19 @@ USING: tools.test math arrays kernel sequences ;
}
}
] [ { 1 2 3 3 2 1 } trends ] unit-test
[ { { 2 2 } { 3 3 3 3 } { 4 } { 5 } } ]
[
{ 2 2 3 3 3 3 4 5 }
[ [ odd? ] bi@ = ] slice monotonic-slice
[ >array ] map
] unit-test
[
{ { 1 1 1 } { 2 2 2 2 } { 3 3 } }
] [
{ 1 1 1 2 2 2 2 3 3 }
[ [ odd? ] bi@ = ] slice monotonic-slice
[ >array ] map
] unit-test

View File

@ -1,7 +1,8 @@
! Copyright (C) 2008, 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: make namespaces sequences kernel fry arrays compiler.utilities
math accessors circular grouping combinators sorting math.order ;
USING: accessors arrays circular combinators
combinators.short-circuit compiler.utilities fry grouping
kernel make math math.order namespaces sequences sorting ;
IN: splitting.monotonic
<PRIVATE
@ -27,12 +28,16 @@ PRIVATE>
[
dupd '[
[ length iota ] [ ] [ <circular> 1 over change-circular-start ] tri
[ @ not [ , ] [ drop ] if ] 3each
[ @ not [ 1 + , ] [ drop ] if ] 3each
] { } make
dup empty? [ over length 1 - prefix ] when -1 prefix 2 clump
2dup {
[ nip empty? ]
[ [ length ] [ last ] bi* = not ]
} 2|| [ over length suffix ] when
0 prefix 2 clump
swap
] dip
'[ first2 [ 1 + ] bi@ _ _ boa ] map ; inline
'[ first2 _ _ boa ] map ; inline
PRIVATE>