Skip to content

Commit

Permalink
ch08 more reorganizing FilePipe stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
spamegg1 committed Sep 6, 2024
1 parent f617b44 commit 08f3126
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch08
package filePipe
package out

import scalanative.unsigned.{UnsignedRichLong, UnsignedRichInt}
import scalanative.unsafe.*
Expand Down Expand Up @@ -76,7 +75,9 @@ def run: Unit =
given ec: ExecutionContext = ch07.EventLoop

val p = FilePipe(c"./data.txt")
.map(d => { println(s"consumed $d"); d })
.map: d =>
println(s"consumed $d")
d
.addDestination(Tokenizer("\n"))
.addDestination(Tokenizer(" "))
.map(d => d + "\n")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
package ch08
package filePipe
package examples

import scalanative.unsafe.CQuote
import scala.util.Try
import ch07.LibUV.*, ch07.LibUVConstants.*

import ch07.LibUV.*, ch07.LibUVConstants.*, filePipe.FilePipe
@main
def fileInputPipeExample: Unit =
val p = FilePipe(c"./data.txt")
.map: d =>
println(s"consumed $d")
val parsed = Try(d.toInt)
println(s"parsed: $parsed")
parsed.toString // I changed this to make it type-check.
.addDestination(FileOutputPipe(c"./output.txt", false))

object FileInputPipeExample:
@main
def fileInputPipe: Unit =
val p = FilePipe
.apply(c"./data.txt")
.map: d =>
println(s"consumed $d")
d
.map: d =>
val parsed = Try(d.toInt)
println(s"parsed: $parsed")
parsed
// .addDestination(FileOutputPipe(c"./output.txt", false))
uv_run(ch07.EventLoop.loop, UV_RUN_DEFAULT)
println("done")
uv_run(ch07.EventLoop.loop, UV_RUN_DEFAULT)
println("done")

object FileOutputPipeExample:
import filePipe.out.FileOutputPipe
@main
def fileOutputPipe: Unit =
println("hello!")
// val p = SyncPipe(0)
val p = FilePipe.apply(c"./data.txt")
@main
def fileOutputPipeExample: Unit =
println("hello!")
// val p = SyncPipe(0)
val p = FilePipe(c"./data.txt")

val q = p
.map: d =>
println(s"consumed $d")
d
.map: d =>
val parsed = Try(d.toInt)
println(s"parsed: $parsed")
parsed.toString
.addDestination(FileOutputPipe(c"./output.txt", false))
uv_run(ch07.EventLoop.loop, UV_RUN_DEFAULT)
println("done")
val q = p
.map: d =>
println(s"consumed $d")
val parsed = Try(d.toInt)
println(s"parsed: $parsed")
parsed.toString
.addDestination(FileOutputPipe(c"./output.txt", false))

uv_run(ch07.EventLoop.loop, UV_RUN_DEFAULT)
println("done")

// object Stuff:
// import filePipe.*
Expand Down

0 comments on commit 08f3126

Please sign in to comment.