-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3VersionsCSV
More file actions
44 lines (29 loc) · 1.37 KB
/
3VersionsCSV
File metadata and controls
44 lines (29 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
--------------------------version avec accumulateur String --------------------------
def decomposition(fichier: String): String = {
val bufferedSource = io.Source.fromFile(fichier)
val lignes = bufferedSource.getLines()
@tailrec
def lireCSV(l : Iterator[String] = lignes, acc: String = ""): String = l match {
case x if !x.hasNext => acc
case x => lireCSV(x, acc + x.next().split(",").map(x => x.trim).mkString("[", ", ", "]"))
}
lireCSV()}
----------------version ligne par ligne en String
def decomposition(fichier: String): String = {
val bufferedSource = io.Source.fromFile(fichier)
val lignes = bufferedSource.getLines()
def lireCSV(l : Iterator[String] = lignes, acc: String = ""): String = l match {
case x if x.hasNext => println(x.next().split(",").map(x => x.trim).mkString("List(", ", ", ")")) + lireCSV(x)
}
lireCSV()}
--------------------------version qu'on peut appeler avec head ou tail
def decomposition(fichier: String): List[Serializable] = {
val bufferedSource = io.Source.fromFile(fichier)
val lignes = bufferedSource.getLines()
@tailrec
def lireCSV(l : Iterator[String] = lignes, acc: List[Serializable] = Nil): List[Serializable] = l match {
case x if !x.hasNext => acc
case x => lireCSV(x, acc ::: List((x.next().split(",").map(x => x.trim).toList)))
}
lireCSV()}
print(decomposition("C:\\Users\\kevin\\Desktop\\Labs2\\sales1.csv"))