Files
enso/tests/test.nim
2025-12-26 17:36:30 -08:00

45 lines
902 B
Nim

import enso
import std/[os, strformat, sugar]
proc unsafe_void(str: string) =
echo str
proc unsafe_int(str: string): int =
echo str
result = 1
func check_file(name: string): IO[string] =
proc(): string =
if fileExists(name):
result = readFile(name)
else:
result = "Not found"
func main() =
run strput("Hello from Enso!")
let
out_void: IO[void] = lift () => unsafe_void("void")
out_int: IO[int] = lift () => unsafe_int("int")
out_void()
run strput(fmt"{out_int()}")
let get_filename: IO[string] =
proc(): string =
let name: IO[string] = readstr(STDIN)
echo "Enter the file name:"
name()
let
nested: IO[IO[string]] = get_filename.map(check_file)
joined: IO[string] = nested.join
run strput(joined())
let flat: IO[string] = get_filename.flatmap(check_file)
run strput(flat())
when isMainModule:
main()