ST 4U 314: Reading Collections with Streams
Today's Smalltalk 4 You looks at readng objects from collections in Smalltalk - streams are hardly limited to strings. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:
If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.
You can also watch it on YouTube:
Today we'll have a look at reading arbitrary collections via streams. In Smalltalk, streams can be used to read any collection (not just strings). For example: here we set up a ByteArray, and then read from it:
stream := #[12 23 34 78 99] readStream. collection := OrderedCollection new. collection add: stream next. collection skip: 2. collection add: stream next. ^collection
If you inspect the results, you'll see the collection #(12 78). You can do the same with collections of disparate objects:
stream2 := #('one' 2 'four' 16.2 $F 81) readStream. collection2 := OrderedCollection new. collection2 add: stream2 next. collection2 skip: 2. collection2 add: stream2 next. ^collection2
Inspecting the results will give you the collection #('one' 16.2). Next time, we'll look at writing collections using streams.
Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.
Enclosures:
[st4u314-iPhone.m4v ( Size: 2881153 )]