Permalink
Browse files

Merge pull request #10 from lpoulain/patch-2

Add information about the Stream type
  • Loading branch information...
2 parents fc84ac2 + e67ba7d commit feabcf5545855f0785e1b373b22e1d1ec58e12f0 @gzm0 gzm0 committed Oct 30, 2012
Showing with 11 additions and 1 deletion.
  1. +11 −1 CheatSheet.md
View
@@ -269,6 +269,7 @@ Scala defines several collection classes:
### Immutable Collections
- `List` (linked list, provides fast sequential access)
+- `Stream` (same as List, except that the tail is evaluated only on demand)
- `Vector` (array-like type, implemented as tree of blocks, provides fast random access)
- `Range` (ordered sequence of integers with equal spacing)
- `String` (Java type, implicitly converted to a character sequence, so you can treat every string like a `Seq[Char]`)
@@ -356,7 +357,16 @@ Scala defines several collection classes:
myMap get "I" // => Some(1)
myMap.updated("V", 15) // returns a new map where "V" maps to 15 (entry is updated)
// if the key ("V" here) does not exist, a new entry is added
-
+
+ // Operations on Streams
+ val xs = Stream(1, 2, 3)
+ val xs = Stream.cons(1, Stream.cons(2, Stream.empty)) // same as above
+ (1 to 1000).toStream // => Stream(1, ?)
+ x #:: xs // Same as Stream.cons(x, xs)
+ // In the Stream's cons operator, the second parameter (the tail)
+ // is defined as a "call by name" parameter.
+ // Note that x::xs always produces a List
+
## Pairs (similar for larger Tuples)
val pair = ("answer", 42) // type: (String, Int)

0 comments on commit feabcf5

Please sign in to comment.