File tree Expand file tree Collapse file tree 2 files changed +4
-11
lines changed
Expand file tree Collapse file tree 2 files changed +4
-11
lines changed Original file line number Diff line number Diff line change 1515 " package.json"
1616 ],
1717 "dependencies" : {
18- "purescript-arrays" : " * " ,
18+ "purescript-arrays" : " ~0.2.2 " ,
1919 "purescript-tuples" : " *" ,
2020 "purescript-maybe" : " *"
2121 }
Original file line number Diff line number Diff line change @@ -2,30 +2,23 @@ module Data.Unfoldable where
22
33import Data.Maybe
44import Data.Tuple
5+ import Data.Array.ST
56import Control.Monad.Eff
67import Control.Monad.ST
78
89class Unfoldable t where
910 unfoldr :: forall a b . (b -> Maybe (Tuple a b )) -> b -> t a
1011
11- foreign import newEmptySTArray
12- " function newEmptySTArray() {\
13- \ return [];\
14- \}" :: forall eff h a . Eff (st :: ST h | eff ) (STArray h a )
15-
1612instance unfoldableArray :: Unfoldable [] where
1713 unfoldr f b = runPure (runSTArray (do
18- arr <- newEmptySTArray
14+ arr <- emptySTArray
1915 seed <- newSTRef b
20- idx <- newSTRef 0
2116 untilE $ do
2217 b1 <- readSTRef seed
2318 case f b1 of
2419 Nothing -> return true
2520 Just (Tuple a b2) -> do
26- i <- readSTRef idx
27- pokeSTArray arr i a
21+ pushSTArray arr a
2822 writeSTRef seed b2
29- writeSTRef idx (i + 1 )
3023 return false
3124 return arr))
You can’t perform that action at this time.
0 commit comments