File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ ]
You can’t perform that action at this time.
0 commit comments