Git Product home page Git Product logo

toolkit's Introduction

Typelevel Toolkit

A toolkit of great libraries to get started building Typelevel apps on JVM, Node.js, and Native! Our very own flavour of the Scala Toolkit.

//> using toolkit typelevel:default

import cats.effect.*

object Hello extends IOApp.Simple:
  def run = IO.println("Hello toolkit!")

To get started, you can use the accompanying template :

scala-cli --power new typelevel/toolkit.g8

Important

The toolkit does not yet support Scala Native 0.5.x series.

Libraries included

toolkit's People

Contributors

armanbilge avatar kristianan avatar lenguyenthanh avatar mergify[bot] avatar reardonj avatar toniogela avatar typelevel-steward[bot] avatar ubaldop avatar zetashift avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

toolkit's Issues

Example script doesn't print anything

I ran the example code from the README and it doesn't print anything:

➜  toolkit git:(main) ✗ scala-cli toolkit.sc
Compiling project (Scala 3.2.2, JVM)
Compiled project (Scala 3.2.2, JVM)
➜  toolkit git:(main) ✗ 

I'm not sure if this is because of scala-cli or Cats Effect.

Drop Scala 2.12

Scala Toolkit supports 2.12. All of our libraries do so far, so it's not any extra effort to do it here.

But, why. Here you go @SethTisue 😜

Publish for Scala Native 0.5.x

It'd be cool if the toolkit could work with Scala Native 0.5.x (0.5.1 as of me writing this)

scala-cli -e 'println("Hello")' --toolkit typelevel:0.1.25 --native --native-version 0.5.1
# Downloading compiler plugin org.scala-native:::nscplugin:0.5.1
# Downloading Scala Native CLI
# Downloading 4 dependencies and 2 internal dependencies
# [error]  Error downloading org.typelevel:toolkit_native0.5_3:0.1.25
# [error]   not found: /Users/pchabelski/.ivy2/local/org.typelevel/toolkit_native0.5_3/0.1.25/ivys/ivy.xml
# [error]   not found: https://repo1.maven.org/maven2/org/typelevel/toolkit_native0.5_3/0.1.25/toolkit_native0.5_3-0.1.25.pom
# [error]   not found: /Users/pchabelski/Library/Caches/ScalaCli/local-repo/1.2.2/org.typelevel/toolkit_native0.5_3/0.1.25/ivys/ivy.xml
# [error]   No fallback URL found
# [error] COMMAND_LINE

Some fun, simple, examples for common scripts and stuff!

Here's the one posed by Virtus Lab:

Imagine you have a common business problem to solve. You need to write a program that fetches text from a web service and then creates a file in the local filesystem with content and path based on the downloaded information.

Scala Toolkit is getting a bunch of tutorials / examples, we can cheat by copying those and then slapping on a parTraverse 😝

Kitchen Sink import

A common complaint is about the enormous amount of imports it takes to do stuff. e.g. http4s/http4s#6696

What if ... we just exported a bunch of useful stuff under a single package?

package typelevel.toolkit

export cats.*
export cats.effect.*
export fs2.*
export org.http4s.*
export org.http4s.ember.client.EmberClientBuilder
// etc.

Not gonna lie, it's playing with fire a bit. Probably instead of wildcards we should be thoughtful about the specific things we export.

But then:

import typelevel.toolkit.*

and you are off to the races!

v0.1.0

Anything we wanna do prior to a first release? :)

SLF4J Logging Warnings

When I trying running a simple http4s client app with Typelevel Toolkit, I get warnings about SL4FJ at startup:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

I can get rid of them with //> using dep ch.qos.logback:logback-classic:1.5.3
Maybe the toolkit should include a default logging implementation out of the box? I have no interest in remembering to configure logging when I'm trying to do a quick script.

Opinionated default implementations of common tasks in scripts.

Languages like python provide really fast and simple ways to perform most operations, which lends itself very well to scripting.
I think that Scala fails at this, while it's better than Java it's still not great. I don't think this is a problem for most situations.

I do however think it would be very nice if toolkit could provide default implementations of some common tasks in a referential transparent and resource-safe way. An example would be reading and writing files.

I'm pretty new to using CE so I ended up writing this, which I'm not even sure is the correct way to do this.

def fileWriter(path: String): Resource[IO, FileWriter] = 
    Resource.make(IO.blocking(new FileWriter(new File(name))))(file => IO.blocking(file.close()))
def openFile(path: String) : Resource[IO, Source] = 
    Resource.make(IO.blocking(Source.fromFile(path)))(file => IO.blocking(file.close()))

def writeToFile(path: String, content: String) =
    fileWriter(path).use(writer => IO.blocking(writer.write(content)))

if instead similar operations were already implemented for me I think that would be really great. It would at least make it a lot easier to convince other people to use this :)

All of this might obviously be outside of the scope of toolkit as it's a collection of libraries, but it would certainly make it easier to pick up for people who just want something to write small tools with.

Adding tests in CI

It will be helpful to have tests in CI that check that the toolkit is able to compile a few test scripts.

I'm not sure we can achieve something like this, but we can try. WDYT @armanbilge?

Which libraries?

The current choices mirror what's in the official Scala Toolkit (sttp, upickle, oslib). I also added Decline :)

toolkit/build.sbt

Lines 17 to 25 in e644ae5

libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.9.0",
"org.typelevel" %%% "cats-effect" % "3.4.8",
"co.fs2" %%% "fs2-io" % "3.6.1",
"org.http4s" %%% "http4s-ember-client" % "0.23.18",
"io.circe" %%% "circe-core" % "0.14.4",
"org.http4s" %%% "http4s-circe" % "0.23.18",
"com.monovore" %%% "decline" % "2.4.1",
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M3" // not % Test, on purpose :)

But ... it's all bikesheddable :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.