Skip to content

Commit

Permalink
Adding docu for PersistentVector - references #2
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 10, 2013
1 parent fbad4a8 commit 2ca156b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion help/PersistentHashMap.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ find 42 m
let stringBasedMap = ofSeq [("a",1); ("b",2); ("c",3); ("d",4); ("e",5)]
// [fsi:val stringBaseMap : FSharpx.Collections.PersistentHashMap<string,int>]

// Square all values in a map
// Square all values in a HashMap
let stringBasedMap' = map (fun x -> x * x) stringBasedMap
stringBasedMap'.["d"]
// [fsi:val it : int = 16]
Expand Down
45 changes: 45 additions & 0 deletions help/PersistentVector.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,51 @@ A Vector is a collection of values indexed by contiguous integers. Vectors suppo

open FSharpx.Collections.PersistentVector

// Create a new vector and add some items to it
let v =
empty
|> conj "hello"
|> conj "world"
|> conj "!"

// [fsi:val v : FSharpx.Collections.PersistentVector<string>]

// lookup some items and print them to the console
nth 0 v
// [fsi:val it : string = "hello"]
nth 1 v
// [fsi:val it : string = "world"]
v.[2]
// [fsi:val it : string = "!"]

(**
PersistentVectorss are immutable and therefor allow to create new version without destruction of the old ones.
*)

let v' =
v
|> conj "!!!"
|> update 0 "hi" // replace existing value

nth 0 v'
// [fsi:val it : string = "hi"]
nth 3 v'
// [fsi:val it : string = "!!!"]

nth 0 v
// [fsi:val it : string = "hello"]

(** There a couple of interesting operations on PersistentVectors:
*)

// Convert a sequence of values to a PersistentVectors
let intVector = ofSeq [1..10]
// [fsi:val intVector : FSharpx.Collections.PersistentVector<int>]

// Square all values in a PersistentVector
let intVector' = map (fun x -> x * x) intVector
intVector'.[3]
// [fsi:val it : int = 256]

(**
Expand Down

0 comments on commit 2ca156b

Please sign in to comment.