git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
21 lines 488 B history raw
1module Snapshot.STArray03 where
3import Prelude
5import Control.Monad.ST as ST
6import Data.Array.ST as STArray
8test1 :: forall a b. (a -> b) -> Array a -> Array b
9test1 f as = STArray.run do
10 bs <- STArray.new
11 ST.foreach as \a ->
12 void $ STArray.push (f a) bs
13 pure bs
15test2 :: forall a b. (a -> Array b) -> Array a -> Array b
16test2 f as = STArray.run do
17 bs <- STArray.new
18 ST.foreach as \a -> do
19 let as' = f a
20 ST.foreach as' (void <<< flip STArray.push bs)
21 pure bs