@@ -7,48 +7,48 @@ lazy evaluation, indices and joins.
77
88Simple sequential processing:
99``` Go
10- people := csvplus.CsvFileDataSource (" people.csv" ).SelectColumns (" name" , " surname" , " id" )
10+ people := csvplus.CsvFileDataSource (" people.csv" ).SelectColumns (" name" , " surname" , " id" )
1111
12- err := csvplus.Take (people).
13- Filter (csvplus.Like (csvplus.Row {" name" : " Amelia" })).
14- Map (func (row csvplus.Row ) csvplus.Row { row[" name" ] = " Julia" ; return row }).
15- ToCsvFile (" out.csv" , " name" , " surname" )
12+ err := csvplus.Take (people).
13+ Filter (csvplus.Like (csvplus.Row {" name" : " Amelia" })).
14+ Map (func (row csvplus.Row ) csvplus.Row { row[" name" ] = " Julia" ; return row }).
15+ ToCsvFile (" out.csv" , " name" , " surname" )
1616
17- if err != nil {
18- return err
19- }
17+ if err != nil {
18+ return err
19+ }
2020```
2121
2222More involved example:
2323``` Go
24- customers , err := csvplus.Take (
25- csvplus.CsvFileDataSource (" people.csv" ).SelectColumns (" id" , " name" , " surname" )).
26- UniqueIndexOn (" id" )
27-
28- if err != nil {
29- return err
30- }
31-
32- products , err := csvplus.Take (
33- csvplus.CsvFileDataSource (" stock.csv" ).SelectColumns (" prod_id" , " product" , " price" )).
34- UniqueIndexOn (" prod_id" )
35-
36- if err != nil {
37- return err
38- }
39-
40- orders := csvplus.CsvFileDataSource (" orders.csv" ).SelectColumns (" order_id" , " cust_id" , " prod_id" , " qty" , " ts" )
41-
42- return customers.
43- Join (orders, " cust_id" ).
44- Join (products).
45- ForEach (func (row csvplus.Row ) error {
46- // From my sample data prints lines like:
47- // John Doe bought 7 oranges for £0.03 each on 2016-09-14T08:48:22+01:00
48- _ , e := fmt.Printf (" %s %s bought %s %s s for £%s each on %s \n " ,
49- row[" name" ], row[" surname" ], row[" qty" ], row[" product" ], row[" price" ], row[" ts" ])
50- return e
51- })
24+ customers , err := csvplus.Take (
25+ csvplus.CsvFileDataSource (" people.csv" ).SelectColumns (" id" , " name" , " surname" )).
26+ UniqueIndexOn (" id" )
27+
28+ if err != nil {
29+ return err
30+ }
31+
32+ products , err := csvplus.Take (
33+ csvplus.CsvFileDataSource (" stock.csv" ).SelectColumns (" prod_id" , " product" , " price" )).
34+ UniqueIndexOn (" prod_id" )
35+
36+ if err != nil {
37+ return err
38+ }
39+
40+ orders := csvplus.CsvFileDataSource (" orders.csv" ).SelectColumns (" order_id" , " cust_id" , " prod_id" , " qty" , " ts" )
41+
42+ return customers.
43+ Join (orders, " cust_id" ).
44+ Join (products).
45+ ForEach (func (row csvplus.Row ) error {
46+ // From my sample data prints lines like:
47+ // John Doe bought 7 oranges for £0.03 each on 2016-09-14T08:48:22+01:00
48+ _ , e := fmt.Printf (" %s %s bought %s %s s for £%s each on %s \n " ,
49+ row[" name" ], row[" surname" ], row[" qty" ], row[" product" ], row[" price" ], row[" ts" ])
50+ return e
51+ })
5252```
5353
5454For more details see the [ documentation] ( https://godoc.org/github.com/maxim2266/csvplus ) .
@@ -77,7 +77,7 @@ an implementation of the interface for `.csv` files.
7777Type ` Table ` implements sequential operations on a given data source as well as the ` DataSource `
7878interface itself and other iterating methods. All sequential operations are 'lazy', i.e. they are not
7979invoked immediately, but instead they return a new table which, when iterated over, invokes
80- the particular operation. The operations can be chained using so called fluent API .
80+ the particular operation. The operations can be chained using so called fluent interface .
8181The actual iteration over a table only happens when any of the following methods are called:
8282- ` ForEach `
8383- ` IndexOn `
0 commit comments