| // scalaVersion := "3.2.0" | |
| // libraryDependencies ++= Seq( | |
| // libraryDependencies ++= Seq( | |
| // "org.typelevel" %% "cats-core" % "2.8.0", | |
| // "dev.zio" %% "zio" % "2.0.0", | |
| // "org.typelevel" %% "cats-effect" % "3.3.14", | |
| // "org.typelevel" %% "kittens" % "3.0.0", | |
| // "dev.zio" %% "zio-json" % "0.3.0-RC10", | |
| // "io.d11" %% "zhttp" % "2.0.0-RC10" | |
| // ) |
John Belmonte, 2022-Sep
I've started writing a toy structured concurrency implementation for the Lua programming language. Some motivations:
- use it as a simple introduction to structured concurrency from the perspective of Lua (this article)
- learn the fundamental properties of structured concurrency and how to implement them
- share code that could become the starting point for a real Lua library and framework
So what is structured concurrency? For now, I'll just say that it's a programming paradigm that makes managing concurrency (arguably the hardest problem of computer science) an order of magnitude easier in many contexts. It achieves this in ways that seem subtle to us—clearly so, since its utility didn't reach critical mass until around 2018[^sc_birth] (just as control structures like functions, if, and while weren't introduced to languages until long after the first compu
Think of all the arguments you've heard as to why static typing is desirable — every single one of those arguments applies equally well to using types to represent error conditions.
An odd thing I’ve observed about the Scala community is how many of its members believe that a) a language with a sophisticated static type system is very valuable; and b) that using types for error handling is basically a waste of time. If static types are useful—and if you like Scala, presumably you think they are—then using them to represent error conditions is also useful.
Here's a little secret of functional programming: errors aren't some special thing that operate under a different set of rules to everything else. Yes, there are a set of common patterns we group under the loose heading "error handling", but fundamentally we're just dealing with more values. Values that can have types associated with them. There's absolutely no reason why the benefits of static ty
| // these aren't _quite_ functional tests, | |
| // and should all be compile_fail, | |
| // but may be illustrative | |
| #[test] | |
| fn concurrent_set() { | |
| use std::sync::Arc; | |
| let x = Arc::new(Cell::new(42)); | |
| let x1 = Arc::clone(&x); | |
| std::thread::spawn(move || { |
| #![warn(rust_2018_idioms)] | |
| #[derive(Debug)] | |
| pub struct StrSplit<'haystack, D> { | |
| remainder: Option<&'haystack str>, | |
| delimiter: D, | |
| } | |
| impl<'haystack, D> StrSplit<'haystack, D> { | |
| pub fn new(haystack: &'haystack str, delimiter: D) -> Self { |
| import cats.Monad | |
| import cats.effect.concurrent.{Ref, Semaphore} | |
| import cats.effect.{Concurrent, Resource} | |
| import cats.implicits._ | |
| import fs2.{Pipe, Stream} | |
| import fs2.concurrent.{NoneTerminatedQueue, Queue} | |
| /** Represents the ability to enqueue keyed items into a stream of queues that emits homogenous keyed streams. | |
| * |
- Generated by code-examples-manager release 2.4.9-SNAPSHOT
- 659 published examples
- akka-actors-hello-world.sc : Simple akka hello world example
- akka-capitalize-and-print.sc : dump capitalized string coming from stdin using streams
- akka-http-client-json-stream.sc : Fully asynchronous http client call with json streamed response using akka-http will work in all cases, even with chunked responses !
- akka-http-client-json-with-proxy.sc : Fully asynchronous http client call with json response using akka-http will work in all cases, even with chunked responses, this example add automatic http proxy support.
- [akka-http-client-json.sc](https:/
| import akka.actor.ActorSystem | |
| import akka.kafka.ConsumerMessage.CommittableMessage | |
| import akka.kafka.scaladsl.Consumer | |
| import akka.kafka.{ ConsumerSettings, Subscriptions } | |
| import akka.stream.ActorMaterializer | |
| import akka.stream.scaladsl.{ Keep, Sink => AkkaSink } | |
| import org.apache.kafka.common.serialization.StringDeserializer | |
| import scalaz.zio._ | |
| import scalaz.zio.stream.Sink | |
| import scalaz.zio.interop.reactiveStreams._ |