diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-11-15 18:13:44 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-11-15 18:14:09 -0500 |
| commit | 290c72732f21f1cddb3a0f8ec3213e4ec321da14 (patch) | |
| tree | 7c6c939a8d563edda5afddefcc2810d550ede0f3 /api/paths.md | |
| parent | a1884f7a85cbee5a67cf48c9e7b088fdea8b8b38 (diff) | |
Add Path.lines()
Diffstat (limited to 'api/paths.md')
| -rw-r--r-- | api/paths.md | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/api/paths.md b/api/paths.md index c69e91d9..07f0560b 100644 --- a/api/paths.md +++ b/api/paths.md @@ -108,14 +108,14 @@ path | `Path` | The path of the file. | - ```tomo # Safely handle file not being readable: if lines := (./file.txt).by_line() -for line in lines -say(line.upper()) + for line in lines + say(line.upper()) else -say("Couldn't read file!") + say("Couldn't read file!") # Assume the file is readable and error if that's not the case: for line in (/dev/stdin).by_line()! -say(line.upper()) + say(line.upper()) ``` ## Path.can_execute @@ -562,6 +562,26 @@ path | `Path` | The path to check. | - assert (./link).is_symlink() == yes ``` +## Path.lines + +```tomo +Path.lines : func(path: Path -> [Text]?) +``` + +Returns a list with the lines of text in a file or returns none if the file could not be opened. + +Argument | Type | Description | Default +---------|------|-------------|--------- +path | `Path` | The path of the file. | - + +**Return:** A list of the lines in a file or none if the file couldn't be read. + + +**Example:** +```tomo +lines := (./file.txt).lines()! + +``` ## Path.modified ```tomo |
