Comments (5)
Replicated issue at https://scastie.scala-lang.org/tRxoUdXNQpesymVEhkcQfw
from eff.
I have the full solution on my other laptop but I will try to explain and reproduce here. When you want to batch queries you have a bunch of effects returning results upon evaluation
Q[T1], Q[T2], Q[T3]
You also assume that there's a way to "batch" several of those queries into a "batched" one:
Q[Z]
Here Z
is supposed to be the result of invoking the 3 previous queries. The trouble is that this value is supposed to represent the 3 results T1, T2, T3
and if we want to resume the next computations as if nothing was ever batched we need to be able to "distribute" Z
back to T1, T2, T3
.
Now if we come back to your example, you have queries returning ()
. If you aggregate all the queries into a query returning ()
it is impossible to "distribute" back ()
into the number of original ()
expected return values. You can solve this by adding a new case to your ADT to represent the batched calls:
case class UpdateNumFieldBatched(ts: Long, fields: Int, n: Int) extends BatchQuote[List[Unit]]
In the case class above n
represent the number of batched calls.
Then:
-
in
Batchable
you batch the relevant calls intoUpdateNumFieldBatched
and updaten
accordingly -
you define
Z
asList[Unit]
andE
asUnit
-
you interpret
UpdateNumFieldBatched
in your interpreter so that it returnsList.fill(n)(())
This works but unfortunately is completely type-unsafe. Maybe we could try to define laws that a given Batchable
instance + interpreter should satisfy but that doesn't seem obvious to me.
I will send you the code tonight if you cannot write it with the indications above.
from eff.
I figured it was something like that. That makes sense, I actually ditched using it because I needed ordering I just wanted to smash a bunch of the ones next to each other, together.
Seq(
Add(1),
Add(2),
Get(2),
Add(1),
)
= Seq(Add(3), Get(2), Add(1))
So Maybe the answer should be leaving something like this comment in the source code at Batchable, it really isn't explained super well. And you're right, its not really representable in the type system, at least that I could think of.
from eff.
I wonder if the Batchable
interface should be actually generalized to
trait Batchable[T[_]] {
def batch(ts: List[T[Any]]): List[(List[T[Any]], T[Any])]
def distribute(results: List[Any]): List[List[Any]]
}
Super untyped but that leaves you the opportunity to batch exactly what you want:
batch
groups a list of commands into onedistribute
distributes each results to a list of results for each original command
But the opportunity for making mistakes is so big! And also very coupled to how commands are being interpreted. Which makes me this that maybe this is better left to each interpreter to do this dispatch/distribution internally by privately creating batched commands and redistributing results. So my last thought is: maybe I should just drop the functionality and give an example of a batching interpreter?
from eff.
I am closing to close this for now until we can come up with something more sensible.
from eff.
Related Issues (20)
- upgrade to cats-effect 1.0.0-RC3? HOT 5
- Any plans on releasing latest version of Eff ? HOT 4
- How to use fs2.Stream compile for Eff[R, ?] ? HOT 3
- 2.13 support ? HOT 12
- Future maintenance of Eff AddOns (Twitter, Scalaz, Monix, Doobie) HOT 7
- Use scala-steward? HOT 2
- missing 5.7.0 tag on GitHub HOT 1
- Broaden maintainer set HOT 1
- Scalajs 1.x support HOT 1
- Use Mergify for automatically merge scala-steward's PRs? HOT 2
- release new version HOT 5
- migrate to GitHub Actions?
- Cats Effect 3 migration HOT 2
- "Composing ADTs" tutorial code does not work as expected HOT 2
- Widening the effects a computation HOT 9
- ConcurrentWeakIdentityHashMap issue
- update specs2 HOT 1
- old removed branch memo
- remove `-source:3.0-migration` HOT 2
- re-enable scala-native test HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eff.