Skip to content

Commit 8d19d7e

Browse files
authored
Create io.hcs
1 parent 23f9c34 commit 8d19d7e

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

libs/std/lib/io.hcs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
fun read_file_or(path: Str, domyslna: Str) -> Str [
2+
let wynik = read_file(path)
3+
match wynik [
4+
Ok(tresc) -> [
5+
end tresc
6+
]
7+
Err(_e) -> [
8+
end domyslna
9+
]
10+
]
11+
]
12+
13+
!! Sprawdza, czy plik istnieje i da sie go odczytac (bez zwracania
14+
!! tresci) - przydatne przed operacjami, ktore zakladaja jego obecnosc.
15+
fun file_readable(path: Str) -> Bool [
16+
let wynik = read_file(path)
17+
match wynik [
18+
Ok(_tresc) -> [
19+
end true
20+
]
21+
Err(_e) -> [
22+
end false
23+
]
24+
]
25+
]
26+
27+
!! Zapisuje `tresc` do pliku i zwraca `true` przy sukcesie, `false` przy
28+
!! bledzie (bez propagowania szczegolow bledu) - wygodne w miejscach,
29+
!! gdzie interesuje nas tylko czy operacja sie udala.
30+
fun write_file_ok(path: Str, tresc: Str) -> Bool [
31+
let wynik = write_file(path, tresc)
32+
match wynik [
33+
Ok(_v) -> [
34+
end true
35+
]
36+
Err(_e) -> [
37+
end false
38+
]
39+
]
40+
]

0 commit comments

Comments
 (0)