Scala-digest #8 (August 18 – September 4)
Usually we open our digest with the Scala language or compiler related news, but this time there is something more important. Sam Halliday finally completed his book “Functional Programming for Mortals with Scalaz”. Despite the fact that the contents is closely related to the scalaz library, this book is one of the most important contributions into the Scala community. Most chapters can be considered as the missing scalaz documentation. Moreover, the book looks like an excellent guide for a typical std Scala FP/OOP developer into the world of real pure FP life. The practical part is really impressive. In addition to simple examples of the scalaz concepts, there is one real (a non-toy) application developed through the entire book.
In conclusion, you get 300+ pages, an excellent analysis of the scalaz typeclasses hierarchy and data types, historical references, FP terminology and slang explanations for mortals.
It doesn’t matter to which part of the Scala community you belong – reading this book is definitely useful.
During this meeting, no final decisions were made on the first pack of SIPs for Scala 3. Сommittee members summarized community reaction and their opinions.
They decided to add additional information into the SIP about removing auto-application, because the original motivation was related to eta-expansion, not about rules for using empty parameter list for side-effecting methods.
The most interesting discussion was about XML-literals:
- There was opened “name based XML literals” Pre-SIP which on the contrary proposes to improve XML-literal support. The key idea is to use name-based translation from XML to Scala AST. This approach should allow smooth integration with any kind of third-party XML-libraries in addition to getting rid off abandoned and buggy standard scala-xml.
- Mostly, scala-xml is demanded by the frontend development side. There was a good point that probably it could be a mistake to remove XML literals from Scala, while other languages do the opposite, for instance JSX and its Typescript support.
The last M5 milestone of 2.13 was released recently with a huge and impressive changelog. We would like to highlight some, that weren’t mentioned in the previous series:
- Fixed #7838 with the title: “Offer stronger guarantees under the Java Memory model for List, Vector”. Despite the fact that List and Vector are immutable, their implementations contain some dirty mutable state internally (there is a notice in the scaladocs about that). Furthermore, according to JMM, there is no guarantee to get these objects in a correct state if you try to access it from another thread without using synchronization primitives.
Notice: if you are far from being an expert in Java-Memory-Model and this information frightens you, like a digest author, please keep calm. Actually, its hard to come across this situation in the Scala ecosystem, that you are using Futures for multithreading and you know how to use atomic/volatile. To get more information about safe publication we recommend to read this post by Aleksey Shipilëv “Safe Publication and Safe Initialization in Java”, that is mentioned in discussions about that issue.
- String-building using + on non-String types is now deprecated
- Added immutable maps that maintain insertion order (VectorMap/SeqMap)
- Added scala.util.Using, for automatic resource management a la `try with resources` or `bracket` with `map` and `flatMap` method for usage in for-comprehension
- Added Option-returning methods (e.g. toIntOption) for parsing literals
- Added scala.util.chaining object that provides special syntax tap and pipe. Tap allows you to add some side-effecting function before obtaining a value. Pipe to transform a value avoiding introducing a variable binding. Unfortunately, pipe didn’t get its symbol analog (e.x |>) and its documentation says that its usage may have some overhead.
- Now it’s possible to use implicitNotFound annotation right in the method parameter list, not only in class definitions.
Libraries and Tools
Thanks to Oleg Pyzhkov for summary and highlighting:
- Introduce SyncIO for effects which aren’t support asynchronous execution.
- IO can now be canceled by default for any asynchronous tasks
- Fixed: release inside bracket could be executed in a wrong order in case of IO cancel
- Timer was separated into: Clock (for current time), ContextShift (for switching between task pools). Now Timer need only for awaiting (sleep)
Comparing to Scala REPL, Ammonite definitely improved the user experience. On the other hand, it works a little bit slower than std, so users can feel the difference.
Alexandre Archambault decided to dive into this problem and speed it up to 4 times! Now it works faster even than std. Version with this fix is already available in a snapshot-release and used in jupyter-scala 1.0.5
Sébastien Doeraene published a portable-scala-reflect library.
The goal is to provide a general, minimalistic version of the reflection api, which would be supported not only via JVM but also by other platforms: Scala.js, Scala-Native. The library consists of only three units: annotations for marking a class that its information should be available in the runtime, a method for finding such classes by name, and a class on which you can call new Instance or a constructor with parameters. Already has support for JVM and Scala.js.
While going open-source, foundationDB became interesting to the public. With declared features it looks like an excellent candidate for use in pair with akka-persistence.
The release of Scala 2.13 is only expected. So if you really need an alternative toOptionInt and you are tired of manually wrapping calls like toInt into Try or Either, than you can try this library.
In case you didn’t know before how to extract source type from referral traffic, this library is for you. Authors have made a huge effort to typify the large number of places from where the user can get to you.
Configuring auto-publishing in the repository is not the most pleasant task developer has to do. Especially in Sonatype. This plugin along with detailed instructions for presetting can perfectly save time, allowing to set sbt + travis to the repository by the tag.
Edmund Noble published documentation for testz library. It contains a reasonable motivation part with an explanation “why testz” and what is wrong with other testing libraries. Testz has so small core codebase, that probably its size less or equal to the mentioned pitch.
Blogs and Articles
If you recently came to the world of the Scala development, it could be useful to learn about the basic rules of working with Futures. As well as, the reasons why in 2018 it makes sense to start looking at the alternatives.
A view of the modern java world by the Scala developer, with answers to the frequently asked questions like why? how to do smth better? is Scala slow? (we recommend to drop the link into a local java chat)
@nihirash should think „Be afraid of your wishes” after his promise to write on Scala a working implementation of the Lisp-like language that can be used in the project for scripting, if he gets 666 retweets. He is going to publish new articles to track down the progress. The first article is already available.
The article with the analysis of details of working with VT1000 and using Jansi to writing interesting console applications.
- Vadim Chelyshov – Scalalaz co-host(email@example.com, Telegram: @dos65)
- Alexandr Karpov – civillian worker from the world’s best company SEMrush
- Oleg Chirukhin – producer ScalaNews, tech questions (firstname.lastname@example.org, Telegram: @olegchir);
@impurepics – Non-Haskell developer by day, pureboy by night
- Sladki Pirozhochek