Skip to content

Lua Picker #33

@vitiral

Description

@vitiral

I'm really enjoying using Lua.

I've thought for a long time about what the "base type" of the system should be. The basic type is a List of structs, where you can run queries on the structs and there is an index on that array. The structs wouldn't even have to be stored locally -- they could be in the filesystem.

The type to interface with all this will be called a Picker. The default implementation will be a picker on a List of some struct. You retrieve items with Query.

The basic interface looks like

Employee = struct('Employee', {'name', 'birthday', 'salary', 'job'})
p = Picker(listOfEmployees)
-- print managers/vp with salary <= 110,000
print(
  p.isIn{job={'manager', 'vp'})
    .isLte{salary=110000}
)

The picker is not just a view onto the list though: it can contain an lookup of one or more struct fields, which is just a Map[value, List[index]] to say which indexes are at a specific key -- useful for isIn comparisons. Comparable fields can also have a sortedLookup so that lte / etc operators can be found using a binary search (O(logn) instead of O(n)).

A Picker can be backed by either a List or an Iter/function (iterators are implemented as functions in lua, but I also have an Iter type). Each call to a picker method returns a PickerIter, which is an iterator that still has access to the picker data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions