Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method for generic table processing #23

Open
sinlerdev opened this issue Jul 18, 2023 · 4 comments
Open

Add a method for generic table processing #23

sinlerdev opened this issue Jul 18, 2023 · 4 comments
Assignees
Labels
phase: designing Means that the issue is being in the API designing phase. type: feature Means the issue is about feature suggestion. where: API Means the issue is about Vinum's API.

Comments

@sinlerdev
Copy link
Member

While it's not the goal to have something strictly similar to ForX objects, it's generally a good idea to offer some kind of of table processing.

This issue's status is the same as #22.

@sinlerdev sinlerdev added phase: discussion Means that the issue is still being discussed. type: enhancement Means the issue is about improving an already developed feature. where: API Means the issue is about Vinum's API. labels Jul 18, 2023
@sinlerdev sinlerdev moved this to Should in Vinum V0.4 Jul 18, 2023
@sinlerdev sinlerdev removed the status in Vinum V0.4 Jul 18, 2023
@sinlerdev sinlerdev moved this to Should in Vinum V0.4 Jul 18, 2023
@sinlerdev sinlerdev added type: feature Means the issue is about feature suggestion. and removed type: enhancement Means the issue is about improving an already developed feature. labels Jul 21, 2023
@sinlerdev sinlerdev added phase: designing Means that the issue is being in the API designing phase. and removed phase: discussion Means that the issue is still being discussed. labels Aug 7, 2023
@sinlerdev
Copy link
Member Author

I think a very good approach to this issue is to provide a utility function that takes in an input state object (assuming its value is a table), and then computes a table of state objects.

An API for doing that might look like this:

local libraryArray  = Hold({
    "Vinum", "Atticus", "Streamable"
}, ...)

-- In this example, both `key` and `value` are state objectified beforehand.
-- as such, the computer function can efficiently decide whether it needs to care 
-- about the key/value
local libraryDictonary = InTable(libraryArray, function(use, key, value)
    return "Library", use(value)
end)

for key, stateObj in libraryDictonary do -- Remember: InTable returns a table of state objects!
    print(key, stateObj:get() -- This prints "Library Vinum/Atticus/Streamable".
end

Plus, cases where a state object needs to recompute its key (either the key changed, or removed entirely), we could store a reference to the key, and when any operations concerning keys/indexes are needed to be done, we could do it without making it vulnerable to bugs.

I also think that InTable should error when two objects try to use the same key, but thats an implementation detail.

@xiyler xiyler moved this from Should to Could in Vinum V0.4 Feb 6, 2024
@xiyler xiyler self-assigned this Feb 6, 2024
@xiyler xiyler removed this from Vinum V0.4 Feb 6, 2024
@xiyler
Copy link
Contributor

xiyler commented Feb 6, 2024

Deferred to 0.5

@xiyler
Copy link
Contributor

xiyler commented Mar 8, 2024

An alternative design that I am leaning towards more is something like this:

local projects = scope:Source({Vinum = true, reactifiy = false, codify = false})
-- NOTE: InTable should be able to also work with BulkCreate's resultant tables.
local libraries = scope:InTable(projects, function(key, value)
   if not value then
      return nil
   end
   return key(), true
end)

for libraryName in Read(libraries) do
   print(libraryName)
end

-- prints:
-- "Vinum"

@xiyler xiyler changed the title An equivalent to Fusion's ForX objects Add a method for generic table processing Mar 8, 2024
@xiyler
Copy link
Contributor

xiyler commented Mar 11, 2024

Deferred to Vinum 0.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
phase: designing Means that the issue is being in the API designing phase. type: feature Means the issue is about feature suggestion. where: API Means the issue is about Vinum's API.
Projects
None yet
Development

No branches or pull requests

2 participants