mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-06-11 06:29:33 +00:00
with file reader
This commit is contained in:
parent
26a1e8c823
commit
d4410bcde3
2
data/example.txt
Normal file
2
data/example.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
foo
|
||||||
|
bar
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.htmlism.firepower.demo
|
||||||
|
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
case class File(path: Path)
|
||||||
|
|
||||||
|
object File:
|
||||||
|
def apply(first: String, fragments: String*): File =
|
||||||
|
File(Path.of(first, fragments: _*))
|
|
@ -1,8 +1,11 @@
|
||||||
|
package com.htmlism.firepower.demo
|
||||||
|
|
||||||
import zio.*
|
import zio.*
|
||||||
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
object PrintPrograms extends ZIOAppDefault:
|
object PrintPrograms extends ZIOAppDefault:
|
||||||
def run: IO[IOException, Unit] =
|
def run: ZIO[Any, Throwable, Unit] =
|
||||||
Console
|
File("data/example.txt")
|
||||||
.printLine("Hello, World!")
|
.contents
|
||||||
|
.map(println)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.htmlism.firepower
|
||||||
|
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
import zio.*
|
||||||
|
|
||||||
|
package object demo:
|
||||||
|
implicit class FileOps(f: demo.File):
|
||||||
|
def contents: Task[String] =
|
||||||
|
ZIO.attempt {
|
||||||
|
Files.readAllBytes(f.path)
|
||||||
|
}.map(xs => new String(xs, Charset.defaultCharset()))
|
Loading…
Reference in New Issue
Block a user