Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
There's a usecase to allow one to acquire resources, where certain resources depend on other resources.
In the above example, the
b
is a resource that depends on thea
resource.I'm using the new getter feature of JS objects, where
this
is used to refer to the original object.However here,
this.a
would actually be the resource acquisition, and not the resource actually acquired.The types of
Resources
would change to like this:There are a few problems though:
get prop
) providing lazy evaluation. This means that infinite loops can happen.get prop
is what keeps thethis
referencing the object. But we don't actually want the property of theResourceAcquires
. We want theResource
itself. Thereforethis.a
isn't exactly accurate unless we are going to change whatthis
points to, and make it point to the actual realised resources.this.a
may not yet be acquired at that point.this.a
can be referred to and you can acquire the resource by first acquiringb
. This means you get a sort of a DAG of acquisitions.this.a[1]
to get theResource
.Alternatively since
ResourceAcquire
is already functions, you can instead pass in an object referencing the resulting resources.In this situation, the
a
is actually theResource
and not theResourceAcquire<A>
.However we still have a problem, how do we ensure ordering here. Now
b
has a hard dependency ofa
, but calling it will pass the acquired resources object. You wouldn't know the order required.It seems like we need to use a key-value list instead:
Here the array enables users to control which resources must be allocated first. The addition of the key in the tuple is label for each resource.
Then subsequent acquisitions can refer to earlier acquisitions through the label.
It's possible to do this without explicit labels with just indexes:
This final variant seems the most backwards compatible with what we have already, and it should be a rather simple change. Each subsequent acquisition call is given the array of resources already acquired. Now subsequent acquisitions can be parameterised by earlier acquisitions.
Issues Fixed
Final checklist