Added lot more example code. (0.39.8).
This commit is contained in:
parent
3b70d6c92a
commit
564999709c
32 changed files with 1353 additions and 53 deletions
37
examples/io/csv_reader.fun
Executable file
37
examples/io/csv_reader.fun
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2026 Johannes Findeisen
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2026-03-25
|
||||
*/
|
||||
|
||||
#include <strings.fun>
|
||||
|
||||
path = "./examples/data/sample.csv"
|
||||
|
||||
// Very small CSV reader (no quotes/escapes) for demo purposes
|
||||
fun parse_csv_line(line)
|
||||
return str_split(str_trim(line), ",")
|
||||
|
||||
data = read_file(path)
|
||||
if (len(data) == 0)
|
||||
print("No CSV content at: " + path)
|
||||
else
|
||||
rows = str_split(data, "\n")
|
||||
for row in rows
|
||||
if (len(str_trim(row)) == 0) continue
|
||||
cols = parse_csv_line(row)
|
||||
print("ROW: " + to_string(cols))
|
||||
|
||||
/* Expected output (from examples/io/sample.csv):
|
||||
ROW: [array n=3]
|
||||
ROW: [array n=3]
|
||||
ROW: [array n=3]
|
||||
ROW: [array n=3]
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue