Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //const:
- [<Literal>]
- let notImportantString= "blahBlah"
- let mutable COUNT = 1.0
- //funcs:
- //addNumber --> add the sequence number COUNT to each file.
- let addNumber (file : string) =
- let mutable str = File.ReadAllText(file)
- printfn "%s" str//just for check
- let num = COUNT.ToString()
- let str4 = str + " " + num + "nnn DONE"
- COUNT <- COUNT + 1.0
- let str2 = File.WriteAllText(file,str4)
- file
- //matchFunc --> check if is ".txt"
- let matchFunc (file : string) =
- file.Contains(".txt")
- //allFiles --> go through all files of a given dir
- let allFiles dir =
- seq
- { for file in Directory.GetFiles(dir) do
- yield file
- }
- ////////////////////////////
- let dir = "D:FSharpTesting"
- let a = allFiles dir
- |> Seq.filter(matchFunc)
- |> Seq.map(addNumber)
- printfn "%A" a
- let a = allFiles dir
- |> Seq.filter(matchFunc)
- |> Seq.map(addNumber)
- |> Seq.iter ignore // Forces the sequence to execute
- module Counter =
- let mutable count = 1
- open Counter
- count <- count + 1
- let count =
- let i = ref 0
- fun () ->
- incr i
- !i
- let one = count()
- let two = count()
- var lazyseq = "abcdef".Select(a => print a); //does not do anything
- var b = lazyseq.ToArray(); //will evaluate the sequence
- let isNebraskaCity_bad city =
- let cities =
- printfn "Creating cities Set"
- ["Bellevue"; "Omaha"; "Lincoln"; "Papillion"]
- |> Set.ofList
- cities.Contains(city)
- let isNebraskaCity_good =
- let cities =
- printfn "Creating cities Set"
- ["Bellevue"; "Omaha"; "Lincoln"; "Papillion"]
- |> Set.ofList
- fun city -> cities.Contains(city)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement