Quantcast
Channel: User Alec - Stack Overflow
Browsing latest articles
Browse All 44 View Live

Comment by Alec on Concatinating two Flows in Akka stream

source.via(flow1).concat(source.via(flow2)). Note that you are re-running source twice though.

View Article


Comment by Alec on Force tableswitch instead of lookupswitch

@apangin I agree it does not matter for performance, but Java's way is actually the "smaller" bytecode. This is counterintuitive because of the way javap prints out the switch, but tableswitch...

View Article


Comment by Alec on How to compare types of different, generic HLists?

I fear I'm missing something - did you try adding an implicit ser: Serializer[ ReprA, ReprB] argument to def toSerializedKeys? In fact, why can't Serializer.toBufs be the function presented to users?

View Article

Comment by Alec on Regular expression to find URLs within a string

@TrophyGeek I think you just copied the regex from the first comment, and Akshay forgot to include the &. The right version would be: val urlRegex =...

View Article

Comment by Alec on When should I use ConcurrentSkipListMap?

It feels a little bit weird to benchmark the performance of a datastructure meant for concurrent access only single threaded. This would be more interesting with more threads (even just -tc 1,2,4,8 to...

View Article


Comment by Alec on What is the simplest way to pipe from a Read to a Write

@infogulch because read methods from Read and write methods from Write both require &mut self. As for the why behind that, I'd say it is safe to say that most implementations of read and write will...

View Article

Comment by Alec on Fastest way to invoke method handle fields

No, they aren’t

View Article

Comment by Alec on Fastest way to invoke method handle fields

I definitely could use invokedynamic with a this argument and a getter bootstrap argument, but I buy that I won't get anything more out of it than invokeExact.

View Article


Answer by Alec for Scala and Akka HTTP: Processing form-data requests

If all you want are the string values in the form data, you just need to unmarshal to StrictForm, and then unmarshal each of the field values as strings.Here's a proof of concept Ammonite script that...

View Article


Answer by Alec for akka http: Server Binding not behaving as expected

As the snippet tells, I am terminating the server binding after 10 seconds. So I expect that if I send the request before this period expires, I should get message 'Accepted incoming connection...

View Article

Answer by Alec for passing an Akka stream to an upstream service to populate

The real issue here is that the Azure API is not designed for back-pressuring. There is no way for the output stream to signal back to Azure that it is not ready for more data. To put it another way:...

View Article

Answer by Alec for How to build an Akka Streams Source from the Akka Event...

This seems like an XY problem. If the publisher and subscriber end up de-coupled, what should happen if the publisher produces data faster than the subscriber?With that said, here's a way to do what...

View Article

Answer by Alec for Recover on Akka ask based on the message sent

Akka's ask method is actually pretty easy to recreate - it is just a mapAsync with some extra logic for better errors when the actor dies (see the code). As such, just use mapAsync manually so you can...

View Article


Answer by Alec for Where do enqueued messages go after an actor is stopped Akka

In general, you can't assume much about delivery to dead letters. As the docs on dead letters say:Messages which cannot be delivered (and for which this can be ascertained) will be delivered to a...

View Article

Answer by Alec for Scaladoc generation fails when referencing methods...

This is a bug in Scala, still present in 2.13. This gist of the issue is that when compiling for Scaladoc (as with sbt doc), the compiler introduces extra DocDef AST nodes for holding comments. Those...

View Article


Answer by Alec for How to use type-level functions to create static types,...

Given Scala is one of the tagged languages, here is a solution in Dotty (aka. Scala 3). Take this with a grain of salt, since Dotty is still under development. Tested with Dotty version 0.24.0-RC1,...

View Article

Answer by Alec for No instance for Foldable arising from length inside lambda

You likely are intending to filter over list, so to make your code work, you need to also add list as an argument of filter:rpt chr list = map (\chr -> length $ filter (== chr) list) listFor...

View Article


Answer by Alec for How to exit akka stream after n elements recieved?

Just to add on to the answer you found, it is also possible to express things more directly without via:Source<String, NotUsed> sourceStringsFromKinesisRecords = sourceKinesisBasic .map(record...

View Article

How to do a `getOrElseComplete` on `Promise`?

Does it make sense to have an operation like getOrElseComplete that tries to complete a Promise with a value but, if the Promise is already completed, returns the existing completed value instead....

View Article

Why does a reference in the JVM not take two stack slots [duplicate]

Looking at the JVM 15 specification (first two sections here), I see thatreference, int, and float take only one local variable slot and one stack slotlong and double, take 2 slotsEverything in the...

View Article

Answer by Alec for Maximum number of local variables in a Java Method

I'm surprised by the lack of straight answer to this clear question, so here goes: the JVM has a max frame size of 65535 locals and max stack size of 65535, with long and double consuming 2 slots per...

View Article


JVM optimizations for `PermittedSubclasses`

Sealed classes/interfaces were added to Java with JEP 360. The JVM-level change was to add a PermittedSubclasses attribute to class files, which can be used to explicitly list out which classes are...

View Article


How to mimic `tableswitch` using `MethodHandle`?

Context: I've been benchmarking the difference between using invokedynamic and manually generating bytecode (this is in the context of deciding whether a compiler targeting the JVM should emit more...

View Article

Is `BoundedSourceQueue` from `Source.queue` ok with concurrent producers?

Source.queue recently added an overload which specializes to OverflowStrategy.dropNew and avoids the async mechanism. The result of materializing this is a BoundedSourceQueue[T] (compared to...

View Article

Idiomatic way to turn an owned value into a reference with arbitrary lifetime

Consider the following typepub struct Foo<'a> { bar: &'a str,}If I try making a constructor for this type using a String, I'll run into errors about bar not living long enough:impl<'a>...

View Article


Answer by Alec for Why are Scala's LazyList's elements displayed as...

Instead of using LazyList.apply, any of the following work (without evaluating their arguments):LazyList.tabulate(3)(fun)fun(1) #:: fun(2) #:: fun(3) #:: LazyList.emptyLazyList.range(1, 4).map(fun)Why...

View Article

Answer by Alec for Does java support and optimize away tail-recursive calls?

Java and the JVM do not currently support tail callsThe fundamental work that needs to happen is at the level of the JVM, not Java. There has been a slow moving line of work to address this (initially...

View Article

Image may be NSFW.
Clik here to view.

Table class for tables that, when too wide split all their cells into rows

I am trying to figure out what HTML / CSS I need to get a certain breaking behavior depending on how much space is available. Basically, I want to have a long line of text automatically break at...

View Article

Finding the second matching implicit

Consider the following setup:trait Foo[A]object Foo extends Priority2trait Priority0 { implicit def foo1: Foo[Int] = new Foo[Int] {}}trait Priority1 extends Priority0 { implicit def foo2: Foo[Boolean]...

View Article



Answer by Alec for How to bring type information into value level in Haskell?

It boils down to finding what you want to do with that type information. In either case, the modules you will probably be looking at are Data.Typeable and Data.Data. At the center of these modules are...

View Article

Cross-building Scala libraries

I would like to cross-build some of my Bazel targets to Scala 2.12 and 2.13. As a further point of complexity, I need to be able to express cross-target dependencies (eg. some 2.13 target may have a...

View Article

Future of roles for GADT-like type variables?

A question from yesterday had a definition of HList (from the HList package) that uses data families. Basically:data family HList (l :: [*])data instance HList '[] = HNilnewtype instance HList (x ':...

View Article

Lifetime of arena in long-running web server

I'm working on a compiler pipeline and am not sure how to properly model ownership of ASTs with arenas.I have types inside the AST represented as references into arenas (quite like rustc's own TyCtxt),...

View Article


Comment by Alec on Python: can generators be recursive?

@Yuta73 yes, it is

View Article

Comment by Alec on Add sources for unmanaged JARs in SBT

@GaëlJ yeah, I want to provide the sources in the IDE (eg. goto-definition). I'm using Metals, but tracing through both the integration through Bloop and SBT directly, things come back to...

View Article

Comment by Alec on Add sources for unmanaged JARs in SBT

Un-jarring will have other jarring (haha) consequences though. It means that jumping to definition will not longer bring people into a JAR, it'll just be a source file (this is an annoyance I'd be...

View Article


Given two absolute paths, how can I express one of the paths relative to the...

I think this should be quite doable, given that there is a nice function canonicalize which normalizes paths (so I can start by normalizing my two input paths) and Path and PathBuf give us a way of...

View Article


Answer by Alec for Add sources for unmanaged JARs in SBT

Posting what I ended up actually doing in case it is useful for others...My interest in source JARs was in order to have the SBT BSP do the right thing for jumping to definitions of unmanaged JARs. I...

View Article
Browsing latest articles
Browse All 44 View Live


Latest Images