@@ -4,7 +4,7 @@ import Prelude
44import Control.Monad.Eff (Eff )
55import Control.Monad.Eff.Console (log , CONSOLE )
66import Control.Monad.ST (ST , pureST )
7- import Data.Array.ST (STArray , emptySTArray , freeze , peekSTArray , pokeSTArray , pushAllSTArray , pushSTArray , spliceSTArray , thaw , toAssocArray , unsafeThaw , unsafeFreeze )
7+ import Data.Array.ST (STArray , emptySTArray , freeze , peekSTArray , pokeSTArray , pushAllSTArray , pushSTArray , sort , sortBy , sortWith , spliceSTArray , thaw , toAssocArray , unsafeThaw , unsafeFreeze )
88import Data.Foldable (all )
99import Data.Maybe (Maybe (..), isNothing )
1010import Test.Assert (assert , ASSERT )
@@ -132,6 +132,21 @@ testArrayST = do
132132 void $ pokeSTArray arr 1 2
133133 pure arr) == [1 ]
134134
135+ log " sort should reorder a list into ascending order based on the result of compare"
136+ assert $ run (
137+ sort =<< unsafeThaw [1 , 3 , 2 , 5 , 6 , 4 ]
138+ ) == [1 , 2 , 3 , 4 , 5 , 6 ]
139+
140+ log " sortBy should reorder a list into ascending order based on the result of a comparison function"
141+ assert $ run (
142+ sortBy (flip compare) =<< unsafeThaw [1 , 3 , 2 , 5 , 6 , 4 ]
143+ ) == [6 , 5 , 4 , 3 , 2 , 1 ]
144+
145+ log " sortWith should reorder a list into ascending order based on the result of compare over a projection"
146+ assert $ run (
147+ sortWith id =<< unsafeThaw [1 , 3 , 2 , 5 , 6 , 4 ]
148+ ) == [1 , 2 , 3 , 4 , 5 , 6 ]
149+
135150 log " spliceSTArray should be able to delete multiple items at a specified index"
136151
137152 assert $ run (do
0 commit comments