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)
- Integrate under-documented APIs into tutorials
- Explore safer interpretations of `deriveScope` HOT 1
- Spring setters don't work immediately after construction
- Memoise special key generation functions
- Poor typechecking for use functions with UsedAs<T>
- Derive scopes with additional methods HOT 2
- Standard set of reactive graph shapes for testing HOT 1
- Write tutorial for `Safe` expressions
- Broken default props link (still uses .lua)
- "The class type 'TextLabel' has no assignable property 'TextColor3'" when using ForValues (and ForPairs) HOT 1
- Do not rollback errors HOT 6
- Remove all `:destroy()` methods from Fusion HOT 5
- Drop 0.x from the version number HOT 1
- `Spring` scales velocity across speed changes HOT 1
- ForValues inconsistency HOT 1
- Decouple TweenInfos from Tweens HOT 1
- Don't allow varadics in Scope constructors HOT 2
- Add `Child` constructor function for improved type checking
- Nicknaming API for improved debugging
- Allows developers to specify limits on internal consistency
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.