Skip to content

Instantly share code, notes, and snippets.

@jdegoes
Created May 15, 2020 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdegoes/5901dd63b4a0fff8aadc2910d051e9f9 to your computer and use it in GitHub Desktop.
Save jdegoes/5901dd63b4a0fff8aadc2910d051e9f9 to your computer and use it in GitHub Desktop.
package zio.connect
import zio._
import zio.stream._
trait S3Connector {
// Powered by ZIO S3
type S3Connector
type S3Credentials
type S3Exception
type ConnectionError
def s3Layer: ZLayer[S3Credentials, ConnectionError, S3Connector] = ???
sealed case class ObjectId(bucketName: String, key: String)
def getObject(bucketName: String, key: String): ZStream[S3Connector, S3Exception, Byte] = ???
def putObject(bucketName: String, key: String): ZSink[S3Connector, S3Exception, Byte, Unit] =
???
def deleteObjects: ZSink[S3Connector, S3Exception, ObjectId, Unit] =
???
def move(locator: ObjectId => ObjectId): ZSink[S3Connector, S3Exception, ObjectId, Unit] =
???
}
package object s3 extends S3Connector
trait FileConnector {
// Powered by ZIO NIO
import java.nio.file.Path
import java.io.IOException
type FileConnector = Has[FileConnector.Service]
object FileConnector {
trait Service {
def listPaths(path: Path): Stream[IOException, Path]
}
}
def listPaths(path: Path): ZStream[FileConnector, IOException, Path] =
ZStream.accessStream[FileConnector](_.get.listPaths(path))
def readPath(path: Path): ZStream[FileConnector, IOException, Byte] = ???
def writePath(path: Path): ZSink[FileConnector, IOException, Byte, Unit] = ???
def delete: ZSink[FileConnector, IOException, Path, Unit] = ???
def move(locator: Path => Path): ZSink[FileConnector, IOException, Path, Unit] = ???
}
package object file extends FileConnector
trait KafkaConnector {
// Powered by ZIO Kafka
type KafkaSettings
type KafkaConnector = Has[KafkaConnector.Service]
type ConnectionError
object KafkaConnector {
trait Service
}
import java.io.IOException
def kafkaLayer: ZLayer[KafkaSettings, ConnectionError, KafkaConnector] = ???
def subscribe(topics: String): ZStream[KafkaConnector, IOException, Byte] = ???
}
package object kafka extends KafkaConnector
// ZIO S3, ZIO FTP
object example {
import zio.connect.s3._
getObject("foo", "bar") >>> putObject("baz", "buz")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment