on master help sign in
Make the array docs clearer

Use more efficient array transformation example

commit63aae127c122348d11906e6c50884dd55b5c3527 authorHarendra Kumar <harendra@composewell.com> dateThu 18 Jan 2024, 16:48 (3 years ago) parent944e248
1 file changed+4−5
core/src/Streamly/Data/Array.hs+4−5
core/src/Streamly/Data/Array.hs+4−5
@@ -126,7 +126,7 @@ import Prelude hiding (read, length)
126126--
127127-- Convert array to stream, transform, and fold back to array:
128128--
129−-- >>> amap f arr = Array.read arr & fmap f & Stream.fold Array.create
129+-- >>> amap f arr = Array.read arr & fmap f & Stream.fold (Array.createOf (Array.length arr))
130130-- >>> amap (+1) (Array.fromList [1,2,3::Int])
131131-- fromList [2,3,4]
132132--
@@ -153,12 +153,11 @@ import Prelude hiding (read, length)
153153-- See the 'fromPureStream' unreleased API to generate an array from an
154154-- Identity stream safely without using MonadIO constraint.
155155--
156−--
157156-- Note that 'Identity' streams can be generalized to IO streams:
158157--
159−-- >>> pure = Stream.fromList [1,2,3] :: Stream Identity Int
160−-- >>> generally = Stream.morphInner (return . runIdentity)
161−-- >>> Stream.fold Array.create (generally pure :: Stream IO Int)
158+-- >>> stream = Stream.fromList [1,2,3] :: Stream Identity Int
159+-- >>> pure2IO s = Stream.morphInner (return . runIdentity) s :: Stream IO Int
160+-- >>> Stream.fold Array.create (pure2IO stream)
162161-- fromList [1,2,3]
163162--
164163-- == Programming Tips