mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-10-31 21:07:39 +00:00
two line demo
This commit is contained in:
parent
f3feb1ac06
commit
b2e21182d3
1
data/one-line.txt
Normal file
1
data/one-line.txt
Normal file
@ -0,0 +1 @@
|
||||
one line
|
2
data/two-lines.txt
Normal file
2
data/two-lines.txt
Normal file
@ -0,0 +1,2 @@
|
||||
foo
|
||||
bar
|
@ -0,0 +1,10 @@
|
||||
package com.htmlism.firepower.demo
|
||||
|
||||
case class Line(s: String)
|
||||
|
||||
object Line:
|
||||
def mkString(xs: List[Line]): String =
|
||||
xs
|
||||
.iterator
|
||||
.map(_.s)
|
||||
.mkString("\n")
|
@ -7,12 +7,21 @@ import java.io.IOException
|
||||
import com.htmlism.rufio.withzio._
|
||||
|
||||
object PrintPrograms extends ZIOAppDefault:
|
||||
def run: ZIO[Any, Throwable, Unit] =
|
||||
for {
|
||||
_ <- File("data/out.txt")
|
||||
.writeLine("out")
|
||||
private def writeLine(file: String)(s: String) =
|
||||
File(s"data/$file.txt")
|
||||
.writeLine(s)
|
||||
|
||||
_ <- File("data/example.txt")
|
||||
.contents
|
||||
.map(Console.printLine(_))
|
||||
private val programs =
|
||||
List[(String, String)](
|
||||
"one-line.txt" -> "one line",
|
||||
"two-lines.txt" -> (Line.mkString _)
|
||||
.apply(List("foo", "bar").map(Line(_)))
|
||||
)
|
||||
|
||||
def run: Task[Unit] =
|
||||
for {
|
||||
// just a traverse in slow motion...
|
||||
_ <- programs
|
||||
.map { case (f, s) => File(s"data/$f").writeLine(s) }
|
||||
.foldLeft[Task[Unit]](ZIO.unit)((acc, z) => acc *> z)
|
||||
} yield ()
|
||||
|
Loading…
Reference in New Issue
Block a user