Documentation needs a better example of the use of JArray's...
GordonBGood opened this issue · 2 comments
Description
It will be frustrating for new users to get examples using the Java array instances working without better examples showing how they could be used.
Possible Fix
For example, the following code is an example of how to use a JByteArray folling the format of the Object Array example:
import Java
main :: IO ()
main = java $ do
arr <- arrayFromList integers :: Java a JByteArray
elems <- withObject arr $ mapM aget [0..9]
io $ print elems
withObject arr $ mapM_ (\i -> aset i (fromIntegral i * 2)) [0..9]
arrList <- arr <.> arrayToList
io $ print arrList
where integers = [1..10] :: [Byte]
Context
It took longer than it should have to get a basic test bed working...
As mentioned in #929, once we implement the new interface for Arrays, we'll be sure to update the documentation with better examples and a overall idea of how to go about programming with arrays. Thanks for bringing this up.
I have made a PR #935 with an added example of the use of Java Array's (JByteArray in this case), and also added the expected output below the example.