Comments (7)
Potentially pretty valuable (especially if we can get ipairs
internally for some extra speed), but the workaround of [val] = true
seems good enough for now. This definitely isn't a blocking issue, but could be implemented in the second release!
from fusion.
Ideal for transforming unordered arrays, where order does not matter but duplicates are allowed.
In ForValues, you say this. But doesn't this introduce the initial issue of subtle recalculations?
Nope! The initial issue of subtle recalculations is down to keys being assumed to carry meaning, which they don't in ForValues.
To illustrate:
local array = Value({"Red", "Green", "Blue"})
ComputedPairs(array, function(key, value)
-- notice ComputedPairs gives you the key
-- ComputedPairs has to assume the key could be used to calculate the returned value here
-- therefore, we can't reuse a value if it appears at a different key
return {
colour = value
}
end))
ForValues(array, function(value)
-- here, ForValues doesn't give us the key
-- the key could never be used to calculate the returned value here
-- therefore, we *can* reuse a value if it appears at a different key
return {
colour = value
}
end))
Specifically with respect to duplicate values, the only condition is that two values in the output array never point to the same cached object. ForValues doesn't have to make any further guarantees.
from fusion.
I've decided on an API design for this after much consideration with users.
I plan to replace ComputedPairs with 3 new mapping objects (names being bikeshedded).
ForKeys
Iterates over every pair of the input table. Transforms the key using the processor function (KI) -> KO. Puts transformed key and original value in output table.
Processing only occurs when a key is added. Transformed keys are cached. Values do not trigger processing but are forwarded to the output table directly.
Ideal for transforming sets, where elements are stored as keys.
ForValues
Iterates over every pair of the input table. Transforms the value using the processor function (VI) -> VO. Puts original key and transformed value in output table.
Processing only occurs when a key is added or when a key's value changes to a non-nil value. Transformed values are cached, though care needs to be taken with handling duplicate input values to ensure every value in the output table is unique.
Ideal for transforming unordered arrays, where order does not matter but duplicates are allowed.
ForPairs
Iterates over every pair of the input table. Transforms the pair using the processor function (KI, VI) -> (KO, VO). Puts transformed pair in output table.
Processing only occurs when a key is added or when a key's value changes to a non-nil value. Transformed pairs are cached by key.
Ideal for transforming ordered arrays and dictionaries, where both keys and values carry meaning.
Under this new system there is no direct replacement for ComputedPairs. While this may sound bad, it's actually great - it forces users to consider which behaviour they need, which means Fusion can better optimise for each case without user intervention or cognitive load.
from fusion.
Do we want the optional destructor to be called with the output of For*? Since that's how ComputedPairs
currently works:
processor: (K, VI) -> VO,
destructor: (VO) -> ()?
So the idea would be as follows,
For ForKeys
:
processor: (KI) -> KO,
destructor: (KO) -> ()?
For ForValues
:
processor: (VI) -> VO,
destructor: (VO) -> ()?
For ForPairs
:
processor: (KI, VI) -> (KO, VO)
destructor: (KO, VO) -> ()?
from fusion.
If we're on it, this is a good time to implement #97 along with it. But since that's not quite approved yet, maybe this issue should wait a bit.
from fusion.
Yes - I think that the destructor should be forwarded all returned values from the processor function, including any extra metadata the user wishes to provide (see #97).
from fusion.
Ideal for transforming unordered arrays, where order does not matter but duplicates are allowed.
In ForValues, you say this. But doesn't this introduce the initial issue of subtle recalculations?
from fusion.
Related Issues (20)
- Adjust Oklab gamut clipping to compress chroma only
- Oklab <-> Color3 conversions do not use sRGB transfer functions
- Observer should allow for multiple state objects at once HOT 3
- Typechecking capabilities are dramatically reduced in v0.3 HOT 1
- Should Value:set with force also trigger Computed onChange? HOT 1
- ForValues is not passing 'use' - only value is being passed on the first argument HOT 1
- Fusion for general Lua(u) environments HOT 4
- Support for Roact-like/Class-based components HOT 4
- Allow the Value type to specify what it can be set to HOT 1
- OnChange usage example is the same as the example for OnEvent
- Generalised value destruction HOT 16
- New state objects downstream from in-progress updates see inconsistent dependencies HOT 16
- NaN values break springs HOT 1
- Error boundaries HOT 1
- Look into fuzzing as part of our testing suite
- Add explanations and breakdowns of example place files
- Spring/Tween flickering with hydrated reference HOT 2
- Seems that Fusion 0.3 rbxm file is marked as 0.2 HOT 2
- Add unit tests for NaN self-similarity
- Computed does not capture dependency when Value created inside the callback HOT 2
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 fusion.