-
Notifications
You must be signed in to change notification settings - Fork 9
Adding site #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Adding site #10
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9d92939
Adding site structure
TonioGela 3ddbed5
Running prePR
TonioGela b3371ca
De aggregating docs
TonioGela 6abbf77
Populating index.md
TonioGela cda0eed
Adding examples
TonioGela 7a6ca39
Adding fs2 data csv in readme and site
TonioGela c0ad529
Adding Scala 2 examples to the site
TonioGela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| laika.navigationOrder = [ | ||
| index.md | ||
| examples.md | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,172 @@ | ||||||
| # Examples | ||||||
|
|
||||||
| This page contains examples of how typelevel-toolkit and [Scala CLI] work together to write single file scripts using all the power of the Typelevel's libraries. | ||||||
|
|
||||||
| ## POSTing data and writing the response to a file | ||||||
| This example was written by [Koroeskohr] and taken from the [Virtuslab Blog](https://virtuslab.com/blog/scala-toolkit-makes-scala-powerful-straight-out-of-the-box/). | ||||||
|
|
||||||
| @:select(scala-version) | ||||||
|
|
||||||
| @:choice(scala-3) | ||||||
|
|
||||||
| ```scala mdoc:silent | ||||||
| //> using lib "org.typelevel::toolkit::@VERSION@" | ||||||
|
|
||||||
| import cats.effect.* | ||||||
| import io.circe.Decoder | ||||||
| import fs2.Stream | ||||||
| import fs2.io.file.* | ||||||
| import org.http4s.ember.client.* | ||||||
| import org.http4s.* | ||||||
| import org.http4s.implicits.* | ||||||
| import org.http4s.circe.* | ||||||
|
|
||||||
| object Main extends IOApp.Simple: | ||||||
| case class Data(value: String) | ||||||
| given Decoder[Data] = Decoder.forProduct1("data")(Data.apply) | ||||||
| given EntityDecoder[IO, Data] = jsonOf[IO, Data] | ||||||
|
|
||||||
| def run = EmberClientBuilder.default[IO].build.use { client => | ||||||
| val request: Request[IO] = | ||||||
| Request(Method.POST, uri"https://httpbin.org/anything") | ||||||
| .withEntity("file.txt bunchofdata") | ||||||
|
|
||||||
| client | ||||||
| .expect[Data](request) | ||||||
| .map(_.value.split(" ")) | ||||||
| .flatMap { case Array(fileName, content) => | ||||||
| IO.println(s"Writing data to $fileName") *> | ||||||
| Stream(content) | ||||||
| .through(fs2.text.utf8.encode) | ||||||
| .through(Files[IO].writeAll(Path(fileName))) | ||||||
| .compile | ||||||
| .drain | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
| @:choice(scala-2) | ||||||
|
|
||||||
| ```scala mdoc:reset:silent | ||||||
| //> using lib "org.typelevel::toolkit::0.0.2" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| import cats.effect._ | ||||||
| import io.circe.Decoder | ||||||
| import fs2.Stream | ||||||
| import fs2.io.file._ | ||||||
| import org.http4s.ember.client._ | ||||||
| import org.http4s._ | ||||||
| import org.http4s.implicits._ | ||||||
| import org.http4s.circe._ | ||||||
|
|
||||||
| object Main extends IOApp.Simple { | ||||||
| case class Data(value: String) | ||||||
| implicit val json: Decoder[Data] = Decoder.forProduct1("data")(Data.apply) | ||||||
| implicit val enc: EntityDecoder[IO, Data] = jsonOf[IO, Data] | ||||||
|
|
||||||
| def run = EmberClientBuilder.default[IO].build.use { client => | ||||||
| val request: Request[IO] = | ||||||
| Request(Method.POST, uri"https://httpbin.org/anything") | ||||||
| .withEntity("file.txt bunchofdata") | ||||||
|
|
||||||
| client | ||||||
| .expect[Data](request) | ||||||
| .map(_.value.split(" ")) | ||||||
| .flatMap { case Array(fileName, content) => | ||||||
| IO.println(s"Writing data to $fileName") *> | ||||||
| Stream(content) | ||||||
| .through(fs2.text.utf8.encode) | ||||||
| .through(Files[IO].writeAll(Path(fileName))) | ||||||
| .compile | ||||||
| .drain | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| @:@ | ||||||
|
|
||||||
| ## Command line version of mkString | ||||||
|
|
||||||
| In this example, [fs2] is used to read a stream of newline delimited strings from standard input and to reconcatenate them with comma by default, while [decline] is leveraged to parse the command line options. | ||||||
|
|
||||||
| Compiling this example with [scala-native], adding these directives | ||||||
|
|
||||||
| ```scala mdoc:reset:silent | ||||||
| //> using packaging.output "mkString" | ||||||
| //> using platform "native" | ||||||
| //> using nativeMode "release-fast" | ||||||
| ``` | ||||||
|
|
||||||
| will produce a native executable that can be used in a similar way as the Scala's standard library `.mkString`: | ||||||
|
|
||||||
| ```sh | ||||||
| $ echo -e "foo\nbar" | ./mkString --prefix "[" -d "," --suffix "]" | ||||||
| // [foo,bar] | ||||||
| ``` | ||||||
|
|
||||||
| @:select(scala-version) | ||||||
|
|
||||||
| @:choice(scala-3) | ||||||
| ```scala mdoc:reset:silent | ||||||
| //> using lib "org.typelevel::toolkit::@VERSION@" | ||||||
|
|
||||||
| import cats.effect.* | ||||||
| import cats.syntax.all.* | ||||||
| import com.monovore.decline.* | ||||||
| import com.monovore.decline.effect.* | ||||||
| import fs2.* | ||||||
| import fs2.io.* | ||||||
|
|
||||||
| val prefix = Opts.option[String]("prefix", "").withDefault("") | ||||||
| val delimiter = Opts.option[String]("delimiter", "", "d").withDefault(",") | ||||||
| val suffix = Opts.option[String]("suffix", "The suffix").withDefault("") | ||||||
|
|
||||||
| val stringStream: Stream[IO, String] = stdinUtf8[IO](1024 * 1024 * 10) | ||||||
| .repartition(s => Chunk.array(s.split("\n", -1))) | ||||||
| .filter(_.nonEmpty) | ||||||
|
|
||||||
| // inspired by list.mkString | ||||||
| object Main extends CommandIOApp("mkString", "Concatenates strings from stdin"): | ||||||
| def main = (prefix, delimiter, suffix).mapN { (pre, delim, post) => | ||||||
| val stream = Stream(pre) ++ stringStream.intersperse(delim) ++ Stream(post) | ||||||
| stream.foreach(IO.print).compile.drain.as(ExitCode.Success) | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| @:choice(scala-2) | ||||||
|
|
||||||
| ```scala mdoc:reset:silent | ||||||
| //> using lib "org.typelevel::toolkit::0.0.2" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| import cats.effect._ | ||||||
| import cats.syntax.all._ | ||||||
| import com.monovore.decline._ | ||||||
| import com.monovore.decline.effect._ | ||||||
| import fs2._ | ||||||
| import fs2.io._ | ||||||
|
|
||||||
| // inspired by list.mkString | ||||||
| object Main extends CommandIOApp("mkString", "Concatenates strings from stdin") { | ||||||
| val prefix = Opts.option[String]("prefix", "").withDefault("") | ||||||
| val delimiter = Opts.option[String]("delimiter", "", "d").withDefault(",") | ||||||
| val suffix = Opts.option[String]("suffix", "The suffix").withDefault("") | ||||||
|
|
||||||
| val stringStream: Stream[IO, String] = stdinUtf8[IO](1024 * 1024 * 10) | ||||||
| .repartition(s => Chunk.array(s.split("\n", -1))) | ||||||
| .filter(_.nonEmpty) | ||||||
|
|
||||||
| def main = (prefix, delimiter, suffix).mapN { (pre, delim, post) => | ||||||
| val stream = Stream(pre) ++ stringStream.intersperse(delim) ++ Stream(post) | ||||||
| stream.foreach(IO.print).compile.drain.as(ExitCode.Success) | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| @:@ | ||||||
|
|
||||||
|
|
||||||
| [fs2]: https://fs2.io/#/ | ||||||
| [decline]: https://ben.kirw.in/decline/ | ||||||
| [scala-native]: https://scala-native.org/en/stable/ | ||||||
| [Scala CLI]: https://scala-cli.virtuslab.org/ | ||||||
| [Koroeskohr]: https://github.com/Koroeskohr | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # typelevel-toolkit | ||
|
|
||
| A toolkit of **great libraries** to start building **Typelevel** apps on JVM, Node.js, and Native! | ||
|
|
||
| Our very own flavour of the [Scala Toolkit]. | ||
|
|
||
| ## Overview | ||
|
|
||
| Typelevel toolkit is a meta library that currently includes these libraries: | ||
|
|
||
| - [Cats] and [Cats Effect] | ||
| - [fs2] and [fs2 I/O] | ||
| - [fs2 data csv] and its generic module | ||
| - [Http4s Ember client] | ||
| - [Circe] and http4s integration | ||
| - [Decline Effect] | ||
| - [Munit Cats Effect] | ||
|
|
||
| and it's published for Scala 2.12, 2.13 and 3.2.2. | ||
|
|
||
| To use it with [Scala CLI] use this directive: | ||
| ```scala | ||
| //> using lib "org.typelevel::toolkit::@VERSION@" | ||
| ``` | ||
|
|
||
| Albeit being created to be used with [Scala CLI], typelevel-toolkit can be imported into your `build.sbt` using: | ||
| ```scala | ||
| libraryDependencies += "org.typelevel" %% "toolkit" % "@VERSION@" | ||
| // for native and js | ||
| libraryDependencies += "org.typelevel" %%% "toolkit" % "@VERSION@" | ||
| ``` | ||
|
|
||
| ## Quick Start Example | ||
| @:select(scala-version) | ||
| @:choice(scala-3) | ||
| ```scala mdoc:reset:silent | ||
| //> using lib "org.typelevel::toolkit::@VERSION@" | ||
|
|
||
| import cats.effect.* | ||
|
|
||
| object Hello extends IOApp.Simple: | ||
| def run = IO.println("Hello toolkit!") | ||
| ``` | ||
| @:choice(scala-2) | ||
| ```scala mdoc:reset:silent | ||
| //> using lib "org.typelevel::toolkit::@VERSION@" | ||
|
|
||
| import cats.effect._ | ||
|
|
||
| object Hello extends IOApp.Simple { | ||
| def run = IO.println("Hello toolkit!") | ||
| } | ||
| ``` | ||
| @:@ | ||
|
|
||
| [Scala CLI]: https://scala-cli.virtuslab.org/ | ||
| [Scala Toolkit]: https://github.com/VirtusLab/toolkit | ||
| [Cats]: https://typelevel.org/cats | ||
| [Cats Effect]: https://typelevel.org/cats-effect | ||
| [fs2]: https://fs2.io/#/ | ||
| [fs2 I/O]: https://fs2.io/#/io | ||
| [fs2 data csv]: https://fs2-data.gnieh.org/documentation/csv/ | ||
| [Http4s Ember Client]: https://http4s.org/v0.23/docs/client.html | ||
| [Circe]: https://circe.github.io/circe/ | ||
| [Decline Effect]: https://ben.kirw.in/decline/effect.html | ||
| [Munit Cats Effect]: https://github.com/typelevel/munit-cats-effect |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.