Skip to content

Commit

Permalink
Use uniformly byName params and the implicit trace (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfilip authored Oct 7, 2022
1 parent b071554 commit e264a90
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ trait FileConnector {
final def deleteRecursivelyURI(implicit trace: Trace): ZSink[Any, IOException, URI, Nothing, Unit] =
deleteRecursivelyPath.contramapZIO(a => ZIO.attempt(Path.of(a)).refineToOrDie[IOException])

final def existsFile(file: File)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean] =
final def existsFile(file: => File)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean] =
ZSink.unwrap(
ZIO.attempt(file.toPath).refineToOrDie[IOException].map(path => existsPath(path))
)

final def existsFileName(name: String)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean] =
final def existsFileName(name: => String)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean] =
ZSink.unwrap(
ZIO.attempt(Path.of(name)).refineToOrDie[IOException].map(path => existsPath(path))
)

def existsPath(path: Path)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean]
def existsPath(path: => Path)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean]

final def existsURI(uri: URI)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean] =
final def existsURI(uri: => URI)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean] =
ZSink.unwrap(
ZIO.attempt(Path.of(uri)).refineToOrDie[IOException].map(path => existsPath(path))
)
Expand Down Expand Up @@ -213,7 +213,7 @@ trait FileConnector {
final def tempFile(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, File] =
tempPath.flatMap(p => ZSink.fromZIO(ZIO.attempt(p.toFile).refineToOrDie[IOException]))

final def tempFileIn(dirFile: File)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, File] =
final def tempFileIn(dirFile: => File)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, File] =
ZSink
.fromZIO(ZIO.attempt(dirFile.toPath).refineToOrDie[IOException])
.flatMap(dirPath =>
Expand All @@ -224,7 +224,7 @@ trait FileConnector {
final def tempFileName(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, String] =
tempPath.flatMap(p => ZSink.fromZIO(ZIO.attempt(p.toString).refineToOrDie[IOException]))

final def tempFileNameIn(dirName: String)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, String] =
final def tempFileNameIn(dirName: => String)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, String] =
ZSink
.fromZIO(ZIO.attempt(Path.of(dirName)).refineToOrDie[IOException])
.flatMap(dirPath =>
Expand All @@ -233,12 +233,12 @@ trait FileConnector {

def tempPath(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path]

def tempPathIn(dirPath: Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path]
def tempPathIn(dirPath: => Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path]

final def tempURI(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, URI] =
tempPath.flatMap(p => ZSink.fromZIO(ZIO.attempt(p.toUri).refineToOrDie[IOException]))

final def tempURIIn(dirURI: URI)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, URI] =
final def tempURIIn(dirURI: => URI)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, URI] =
ZSink
.fromZIO(ZIO.attempt(Path.of(dirURI)).refineToOrDie[IOException])
.flatMap(dirPath =>
Expand All @@ -256,24 +256,26 @@ trait FileConnector {
final def tempDirURI(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, URI] =
tempDirPath.flatMap(p => ZSink.fromZIO(ZIO.attempt(p.toUri).refineToOrDie[IOException]))

final def tempDirFileIn(dirFile: File)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, File] =
final def tempDirFileIn(dirFile: => File)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, File] =
ZSink
.fromZIO(ZIO.attempt(dirFile.toPath).refineToOrDie[IOException])
.flatMap(dirPath =>
tempDirPathIn(dirPath)
.flatMap(p => ZSink.fromZIO(ZIO.attempt(p.toFile).refineToOrDie[IOException]))
)

final def tempDirFileNameIn(dirName: String)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, String] =
final def tempDirFileNameIn(
dirName: => String
)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, String] =
ZSink
.fromZIO(ZIO.attempt(Path.of(dirName)).refineToOrDie[IOException])
.flatMap(dirPath =>
tempDirPathIn(dirPath).flatMap(p => ZSink.fromZIO(ZIO.attempt(p.toString).refineToOrDie[IOException]))
)

def tempDirPathIn(dirPath: Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path]
def tempDirPathIn(dirPath: => Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path]

final def tempDirURIIn(dirURI: URI)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, URI] =
final def tempDirURIIn(dirURI: => URI)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, URI] =
ZSink
.fromZIO(ZIO.attempt(Path.of(dirURI)).refineToOrDie[IOException])
.flatMap(dirPath =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ case class LiveFileConnector() extends FileConnector {
}
}

override def existsPath(path: Path)(implicit
override def existsPath(path: => Path)(implicit
trace: Trace
): ZSink[Any, IOException, Any, Nothing, Boolean] =
ZSink.fromZIO {
Expand Down Expand Up @@ -188,7 +188,7 @@ case class LiveFileConnector() extends FileConnector {
)
}

override def tempPathIn(dirPath: Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path] = {
override def tempPathIn(dirPath: => Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path] = {

val scopedTempFile: ZIO[Scope, IOException, Path] = {
ZIO.acquireRelease(
Expand All @@ -208,7 +208,7 @@ case class LiveFileConnector() extends FileConnector {
)
}

override def tempDirPathIn(dirPath: Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path] =
override def tempDirPathIn(dirPath: => Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path] =
ZSink.unwrap(
ZIO
.acquireRelease(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private[file] case class TestFileConnector(fs: TestFileSystem) extends FileConne
override def deleteRecursivelyPath(implicit trace: Trace): ZSink[Any, IOException, Path, Nothing, Unit] =
ZSink.foreach(path => fs.deleteRecursively(path))

override def existsPath(path: Path)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean] =
override def existsPath(path: => Path)(implicit trace: Trace): ZSink[Any, IOException, Any, Nothing, Boolean] =
ZSink.fromZIO(fs.exists(path))

override def listPath(path: => Path)(implicit trace: Trace): ZStream[Any, IOException, Path] =
Expand Down Expand Up @@ -66,7 +66,7 @@ private[file] case class TestFileConnector(fs: TestFileSystem) extends FileConne
ZIO.acquireRelease(fs.tempPath)(path => fs.delete(path).orDie).map(path => ZSink.fromZIO(ZIO.succeed(path)))
)

override def tempPathIn(dirPath: Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path] =
override def tempPathIn(dirPath: => Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path] =
ZSink.unwrap(
ZIO
.acquireRelease(fs.tempPathIn(dirPath))(path => fs.delete(path).orDie)
Expand All @@ -80,7 +80,7 @@ private[file] case class TestFileConnector(fs: TestFileSystem) extends FileConne
.map(path => ZSink.fromZIO(ZIO.succeed(path)))
)

override def tempDirPathIn(dirPath: Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path] =
override def tempDirPathIn(dirPath: => Path)(implicit trace: Trace): ZSink[Scope, IOException, Any, Nothing, Path] =
ZSink.unwrap(
ZIO
.acquireRelease(fs.tempDirPathIn(dirPath))(path => fs.deleteRecursively(path).orDie)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,36 @@ package object file {
def deleteRecursivelyURI(implicit trace: Trace): ZSink[FileConnector, IOException, URI, Nothing, Unit] =
ZSink.environmentWithSink(_.get.deleteRecursivelyURI)

def existsFile(file: File)(implicit
def existsFile(file: => File)(implicit
trace: Trace
): ZSink[FileConnector, IOException, Any, Nothing, Boolean] =
ZSink.environmentWithSink[FileConnector](_.get.existsFile(file))

def existsFileName(name: String)(implicit
def existsFileName(name: => String)(implicit
trace: Trace
): ZSink[FileConnector, IOException, Any, Nothing, Boolean] =
ZSink.environmentWithSink[FileConnector](_.get.existsFileName(name))

def existsPath(path: Path)(implicit
def existsPath(path: => Path)(implicit
trace: Trace
): ZSink[FileConnector, IOException, Any, Nothing, Boolean] =
ZSink.environmentWithSink[FileConnector](_.get.existsPath(path))

def existsURI(uri: URI)(implicit
def existsURI(uri: => URI)(implicit
trace: Trace
): ZSink[FileConnector, IOException, Any, Nothing, Boolean] =
ZSink.environmentWithSink[FileConnector](_.get.existsURI(uri))

def listFile(file: => File): ZStream[FileConnector, IOException, File] =
def listFile(file: => File)(implicit trace: Trace): ZStream[FileConnector, IOException, File] =
ZStream.environmentWithStream(_.get.listFile(file))

def listFileName(name: => String): ZStream[FileConnector, IOException, String] =
def listFileName(name: => String)(implicit trace: Trace): ZStream[FileConnector, IOException, String] =
ZStream.environmentWithStream(_.get.listFileName(name))

def listPath(path: => Path): ZStream[FileConnector, IOException, Path] =
def listPath(path: => Path)(implicit trace: Trace): ZStream[FileConnector, IOException, Path] =
ZStream.environmentWithStream(_.get.listPath(path))

def listURI(uri: => URI): ZStream[FileConnector, IOException, URI] =
def listURI(uri: => URI)(implicit trace: Trace): ZStream[FileConnector, IOException, URI] =
ZStream.environmentWithStream(_.get.listURI(uri))

def moveFile(locator: File => File)(implicit
Expand Down Expand Up @@ -108,106 +108,122 @@ package object file {
): ZSink[FileConnector, IOException, URI, Nothing, Unit] =
ZSink.environmentWithSink(_.get.moveURIZIO(locator))

def readFile(file: => File): ZStream[FileConnector, IOException, Byte] =
def readFile(file: => File)(implicit trace: Trace): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.readFile(file))

def readFileName(name: => String): ZStream[FileConnector, IOException, Byte] =
def readFileName(name: => String)(implicit trace: Trace): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.readFileName(name))

def readPath(path: => Path): ZStream[FileConnector, IOException, Byte] =
def readPath(path: => Path)(implicit trace: Trace): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.readPath(path))

def readURI(uri: => URI): ZStream[FileConnector, IOException, Byte] =
def readURI(uri: => URI)(implicit trace: Trace): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.readURI(uri))
def tempFile(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, File] =
ZSink.environmentWithSink[FileConnector](_.get.tempFile)

def tailFile(file: => File, duration: Duration): ZStream[FileConnector, IOException, Byte] =
def tailFile(file: => File, duration: => Duration)(implicit trace: Trace): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.tailFile(file, duration))

def tailFileUsingWatchService(file: => File, duration: Duration): ZStream[FileConnector, IOException, Byte] =
def tailFileUsingWatchService(file: => File, duration: => Duration)(implicit
trace: Trace
): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.tailFileUsingWatchService(file, duration))

def tailFileName(name: => String, duration: Duration): ZStream[FileConnector, IOException, Byte] =
def tailFileName(name: => String, duration: => Duration)(implicit
trace: Trace
): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.tailFileName(name, duration))

def tailFileNameUsingWatchService(name: => String, duration: Duration): ZStream[FileConnector, IOException, Byte] =
def tailFileNameUsingWatchService(name: => String, duration: => Duration)(implicit
trace: Trace
): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.tailFileNameUsingWatchService(name, duration))

def tailPath(path: => Path, duration: Duration): ZStream[FileConnector, IOException, Byte] =
def tailPath(path: => Path, duration: => Duration)(implicit trace: Trace): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.tailPath(path, duration))

def tailPathUsingWatchService(path: => Path, duration: Duration): ZStream[FileConnector, IOException, Byte] =
def tailPathUsingWatchService(path: => Path, duration: => Duration)(implicit
trace: Trace
): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.tailPathUsingWatchService(path, duration))

def tailURI(uri: => URI, duration: Duration): ZStream[FileConnector, IOException, Byte] =
def tailURI(uri: => URI, duration: => Duration)(implicit trace: Trace): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.tailURI(uri, duration))

def tailURIUsingWatchService(uri: => URI, duration: Duration): ZStream[FileConnector, IOException, Byte] =
def tailURIUsingWatchService(uri: => URI, duration: => Duration)(implicit
trace: Trace
): ZStream[FileConnector, IOException, Byte] =
ZStream.environmentWithStream(_.get.tailURIUsingWatchService(uri, duration))

def tempFileIn(file: File)(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, File] =
def tempFileIn(file: => File)(implicit
trace: Trace
): ZSink[FileConnector with Scope, IOException, Byte, Nothing, File] =
ZSink.environmentWithSink[FileConnector](_.get.tempFileIn(file))

def tempFileName(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, String] =
ZSink.environmentWithSink[FileConnector](_.get.tempFileName)

def tempFileNameIn(name: String)(implicit
def tempFileNameIn(name: => String)(implicit
trace: Trace
): ZSink[FileConnector with Scope, IOException, Byte, Nothing, String] =
ZSink.environmentWithSink[FileConnector](_.get.tempFileNameIn(name))

def tempPath(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, Path] =
ZSink.environmentWithSink[FileConnector](_.get.tempPath)

def tempPathIn(path: Path)(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, Path] =
def tempPathIn(path: => Path)(implicit
trace: Trace
): ZSink[FileConnector with Scope, IOException, Byte, Nothing, Path] =
ZSink.environmentWithSink[FileConnector](_.get.tempPathIn(path))

def tempURI(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, URI] =
ZSink.environmentWithSink[FileConnector](_.get.tempURI)

def tempURIIn(uri: URI)(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, URI] =
def tempURIIn(uri: => URI)(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, URI] =
ZSink.environmentWithSink[FileConnector](_.get.tempURIIn(uri))

def tempDirFile(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, File] =
ZSink.environmentWithSink[FileConnector](_.get.tempDirFile)

def tempDirFileIn(file: File)(implicit
def tempDirFileIn(file: => File)(implicit
trace: Trace
): ZSink[FileConnector with Scope, IOException, Byte, Nothing, File] =
ZSink.environmentWithSink[FileConnector](_.get.tempDirFileIn(file))

def tempDirFileName(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, String] =
ZSink.environmentWithSink[FileConnector](_.get.tempDirFileName)

def tempDirFileNameIn(name: String)(implicit
def tempDirFileNameIn(name: => String)(implicit
trace: Trace
): ZSink[FileConnector with Scope, IOException, Byte, Nothing, String] =
ZSink.environmentWithSink[FileConnector](_.get.tempDirFileNameIn(name))

def tempDirPath(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, Path] =
ZSink.environmentWithSink[FileConnector](_.get.tempDirPath)

def tempDirPathIn(path: Path)(implicit
def tempDirPathIn(path: => Path)(implicit
trace: Trace
): ZSink[FileConnector with Scope, IOException, Byte, Nothing, Path] =
ZSink.environmentWithSink[FileConnector](_.get.tempDirPathIn(path))

def tempDirURI(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, URI] =
ZSink.environmentWithSink[FileConnector](_.get.tempDirURI)

def tempDirURIIn(uri: URI)(implicit trace: Trace): ZSink[FileConnector with Scope, IOException, Byte, Nothing, URI] =
def tempDirURIIn(uri: => URI)(implicit
trace: Trace
): ZSink[FileConnector with Scope, IOException, Byte, Nothing, URI] =
ZSink.environmentWithSink[FileConnector](_.get.tempDirURIIn(uri))

def writeFile(file: => File): ZSink[FileConnector, IOException, Byte, Nothing, Unit] =
def writeFile(file: => File)(implicit trace: Trace): ZSink[FileConnector, IOException, Byte, Nothing, Unit] =
ZSink.environmentWithSink(_.get.writeFile(file))

def writeFileName(name: => String): ZSink[FileConnector, IOException, Byte, Nothing, Unit] =
def writeFileName(name: => String)(implicit trace: Trace): ZSink[FileConnector, IOException, Byte, Nothing, Unit] =
ZSink.environmentWithSink(_.get.writeFileName(name))

def writePath(path: => Path): ZSink[FileConnector, IOException, Byte, Nothing, Unit] =
def writePath(path: => Path)(implicit trace: Trace): ZSink[FileConnector, IOException, Byte, Nothing, Unit] =
ZSink.environmentWithSink(_.get.writePath(path))

def writeURI(uri: => URI): ZSink[FileConnector, IOException, Byte, Nothing, Unit] =
def writeURI(uri: => URI)(implicit trace: Trace): ZSink[FileConnector, IOException, Byte, Nothing, Unit] =
ZSink.environmentWithSink(_.get.writeURI(uri))
}

0 comments on commit e264a90

Please sign in to comment.