enso.nim: Shaving off code
This commit is contained in:
17
src/enso.nim
17
src/enso.nim
@ -3,9 +3,8 @@ import std/[options, os, sugar]
|
||||
# Declarations
|
||||
|
||||
type
|
||||
Error* = enum OK, ERR
|
||||
FileDesc* = enum STDIN, STDOUT, STDERR
|
||||
IO*[T] = proc(): T
|
||||
Error* = enum OK, ERR
|
||||
IO*[T] = proc(): T
|
||||
|
||||
func fileread*(file: string): IO[Option[string]]
|
||||
func filewrite*(data: string, file: string): IO[Error]
|
||||
@ -14,7 +13,7 @@ func lift*(fn: proc(): void): IO[void]
|
||||
func lift*[T](fn: proc(): T): IO[T]
|
||||
func join*[T](io: IO[IO[T]]): IO[T]
|
||||
func map*[T, U](io: IO[T], fn: T -> U): IO[U]
|
||||
func readstr*(stream: FileDesc): IO[string]
|
||||
func readln*(fd: File): IO[string]
|
||||
func run*[T](io: IO[T]): T
|
||||
func strput*(str: string): IO[void]
|
||||
func to_IO*[T](val: T): IO[T]
|
||||
@ -60,14 +59,8 @@ func join*[T](io: IO[IO[T]]): IO[T] = map(io, run)
|
||||
func map*[T, U](io: IO[T], fn: T -> U): IO[U] =
|
||||
proc(): U = fn(run(io))
|
||||
|
||||
func readstr*(stream: FileDesc): IO[string] =
|
||||
case stream:
|
||||
of STDIN:
|
||||
lift proc(): string = readLine(stdin)
|
||||
of STDOUT:
|
||||
lift proc(): string = readLine(stdout)
|
||||
of STDERR:
|
||||
lift proc(): string = readLine(stderr)
|
||||
func readln*(fd: File): IO[string] =
|
||||
proc(): string = readLine(fd)
|
||||
|
||||
func run*[T](io: IO[T]): T = io()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user