From 2c319d5ee1da1fbbe51da159090f561c3ca73ba8 Mon Sep 17 00:00:00 2001 From: Omid Bakhshandeh Date: Thu, 18 Jun 2015 13:27:12 -0700 Subject: [PATCH 1/3] first commit --- text/0000-io-target.md | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 text/0000-io-target.md diff --git a/text/0000-io-target.md b/text/0000-io-target.md new file mode 100644 index 0000000..6b467ed --- /dev/null +++ b/text/0000-io-target.md @@ -0,0 +1,57 @@ +# SLIP-NNN - IO Target + +**By: Omid Bakhshandeh** + +This document is provided as a template to get you started. Feel free to add, augment, +remove, restructure and otherwise adapt the structure for what you need after cloning it. +Create a fork of this repository and a new feature branch called slip/NNN (where +NNN is the SLIP number). +This document should be then be copied into slip-NNN/slip-NNN.md. You can also use +this slip-NNN directory to hold any supporting documentation, code and tests. + +## History + +| Date | Version | +|---------------|---------------| +| Jun 18th 2015 | Initial Draft | + +## Motivation + +`scala.io.Source` is one of the most used part of `Scala std`. For many people that are new +to the language and programming IO play an important role. +Scala std doesn't have any support for generating output. Scala programmers use `Java.io` +or `Java.nio` for writing on disk. On the other hand, the incopatibility between Java File +and Scala File makes it hard to have nice Scala code. + +Here, I propose `Scala.io.Target` to be added to std. This part of library could implement the +output version `Scala.io.Source`. + + +### Examples + +An example could be something like this: + +```scala +def fromFile(file: File, bufferSize: Int)(implicit codec: Codec): BufferedSource + +def toFile(file: File, bufferSize: Int)(implicit codec: Codec): BufferedTarget + +``` +It's important to investigate the parts that are a little bit tricky to implement or even impossible like: + +```scala +fromURL(url: URL)(implicit codec: Codec): BufferedSource + +toURL(url: URL)(implicit codec: Codec): BufferedTarget // is it possible to start a simple webserver + //or something like that? +``` + + +## Drawbacks + +The only reason that this library shouldn't be implemented is the richness of Java IO library. If this library +is not good enough that people use it and cannot provide all Java.IO functionality like `ByteWriter` or `Channels`, +then implemeting this library could be a waste of time. + +## Alternatives +There are some alternatives like `Scalaz` and others, but I think this should be really part of Scala std. From c80e6fe263540cb5eed189cfb0764b04b4e2a33f Mon Sep 17 00:00:00 2001 From: Omid Bakhshandeh Date: Thu, 18 Jun 2015 16:04:00 -0700 Subject: [PATCH 2/3] Update 0000-io-target.md --- text/0000-io-target.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/text/0000-io-target.md b/text/0000-io-target.md index 6b467ed..3e88fee 100644 --- a/text/0000-io-target.md +++ b/text/0000-io-target.md @@ -1,13 +1,7 @@ # SLIP-NNN - IO Target **By: Omid Bakhshandeh** - -This document is provided as a template to get you started. Feel free to add, augment, -remove, restructure and otherwise adapt the structure for what you need after cloning it. -Create a fork of this repository and a new feature branch called slip/NNN (where -NNN is the SLIP number). -This document should be then be copied into slip-NNN/slip-NNN.md. You can also use -this slip-NNN directory to hold any supporting documentation, code and tests. +This is a proposal for adding `scala.io.Target` to Scala std. ## History From 5635f04a7d06e56f322fd439ed2b1461a6f5d2b6 Mon Sep 17 00:00:00 2001 From: Omid Bakhshandeh Date: Fri, 19 Jun 2015 09:05:32 -0700 Subject: [PATCH 3/3] Update 0000-io-target.md example for java was added --- text/0000-io-target.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/text/0000-io-target.md b/text/0000-io-target.md index 3e88fee..d921438 100644 --- a/text/0000-io-target.md +++ b/text/0000-io-target.md @@ -40,6 +40,28 @@ toURL(url: URL)(implicit codec: Codec): BufferedTarget // is it possible to star //or something like that? ``` +### Example in Java + +Here is a simple example from java: + +```java +impor java.io.* +Charset charset = Charset.forName("US-ASCII"); +File file = new File(...); +String s = ...; +try (BufferedWriter writer = Files.newBufferedWriter(file, charset)) { + writer.write(s, 0, s.length()); +} catch (IOException x) { + System.err.format("IOException: %s%n", x); +} +``` +and scala version could be something like: + +```scala +impor scala.io.Target._ +String s = ... +Target.toFile(new File(...), s) // File is Scala file, not Java file +``` ## Drawbacks