Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. //const:
  2. [<Literal>]
  3. let notImportantString= "blahBlah"
  4. let mutable COUNT = 1.0
  5.  
  6. //funcs:
  7. //addNumber --> add the sequence number COUNT to each file.
  8. let addNumber (file : string) =
  9. let mutable str = File.ReadAllText(file)
  10. printfn "%s" str//just for check
  11. let num = COUNT.ToString()
  12. let str4 = str + " " + num + "nnn DONE"
  13. COUNT <- COUNT + 1.0
  14. let str2 = File.WriteAllText(file,str4)
  15. file
  16.  
  17. //matchFunc --> check if is ".txt"
  18. let matchFunc (file : string) =
  19. file.Contains(".txt")
  20.  
  21. //allFiles --> go through all files of a given dir
  22. let allFiles dir =
  23.  
  24. seq
  25. { for file in Directory.GetFiles(dir) do
  26. yield file
  27. }
  28.  
  29. ////////////////////////////
  30.  
  31. let dir = "D:FSharpTesting"
  32. let a = allFiles dir
  33. |> Seq.filter(matchFunc)
  34. |> Seq.map(addNumber)
  35. printfn "%A" a
  36.  
  37. let a = allFiles dir
  38. |> Seq.filter(matchFunc)
  39. |> Seq.map(addNumber)
  40. |> Seq.iter ignore // Forces the sequence to execute
  41.  
  42. module Counter =
  43. let mutable count = 1
  44.  
  45. open Counter
  46. count <- count + 1
  47.  
  48. let count =
  49. let i = ref 0
  50. fun () ->
  51. incr i
  52. !i
  53.  
  54. let one = count()
  55. let two = count()
  56.  
  57. var lazyseq = "abcdef".Select(a => print a); //does not do anything
  58. var b = lazyseq.ToArray(); //will evaluate the sequence
  59.  
  60. let isNebraskaCity_bad city =
  61. let cities =
  62. printfn "Creating cities Set"
  63. ["Bellevue"; "Omaha"; "Lincoln"; "Papillion"]
  64. |> Set.ofList
  65.  
  66. cities.Contains(city)
  67.  
  68. let isNebraskaCity_good =
  69. let cities =
  70. printfn "Creating cities Set"
  71. ["Bellevue"; "Omaha"; "Lincoln"; "Papillion"]
  72. |> Set.ofList
  73.  
  74. fun city -> cities.Contains(city)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement