-
Notifications
You must be signed in to change notification settings - Fork 9
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
Opinionated default implementations of common tasks in scripts. #15
Comments
For referentially-transparent, resource-safe APIs for working with files you can look at
I think the quickest way to read a file to a string is: Files[IO].readUtf8(Path(...)).compile.string Unfortunately, I think writing currently needs more boilerplate. Stream.emit(str)
.through(fs2.text.utf8.encode)
.through(Files[IO].writeAll(Path(...)))
.compile.drain Maybe we need a helper for writing in FS2, and some examples in this area. |
Btw: another possibility is that we need a new lib, similar to os-lib, that provides a bunch of helpers on top of |
I think creating another lib is probably the best idea. tos-lib? I'm sure it would be useful in a lot of projects. |
Feel free to pick and choose from what I put together a while ago https://github.com/davenverse/shellfish |
A helper? Btw, examples are a great idea, I'll write some of them for sure [EDIT] ah, that helper! :D |
I wrote that helpers and they got published here Also, to revive this issue, are we considering writing an os-lib? |
I have no experience in writing OS abstraction stuff, but I'll gladly contribute whereever possible! |
Yes, I believe that's what we should do. If anyone has time to work on this, I can review / merge PRs 🙂 The first step can be rewriting what's already there with FS2 I/O so that it's cross-platform (it's currently JVM only). |
It looks like it uses Though I see it uses some JVM only APIs as well: https://github.com/davenverse/shellfish/blob/main/core/src/main/scala/io/chrisdavenport/shellfish/Shell.scala#L158 I'll try to see what currently can be made cross-platform |
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.
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.
The text was updated successfully, but these errors were encountered: