JuliaArrays / JuliaArrays/StructArrays.jl

Request - multiple types & index field

Open
#264 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
402
Forks
49
PR merge metrics
No merged PRs in 30d

Description

Would it be possible to have elements of multiple types with the same supertype, so that

  • fields common to all structs in the array can be called via Array.Field.
    - the array can be filtered for given type via Array(::Type) (or similar syntax)
  • If there is an "ID" field common to all structs, this can be used as a key.
abstract type MyType end

struct A<:MyType
    ID::String
    a::Int
end

struct B<:MyType
    ID::String
    b::Int
end

X = StructArray(      [ A("1",1), A("2",2), B("3",3), B("4",4) ],       parentType = MyType,      Key_Field = :ID   )


X.ID         # [1,2,3,4]

X["1"]       #  A("1",1)       select element by Key field (like a dictionary or named array)

X(::A)      # [A("1",1), A("2",2)]         filter for elements of type A

X(::A).a    # [1,2]                             reference field :a as it is common to elements of type A
X.a          #  Error                            not all elements contain this field

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by reviewing the existing StructArrays indexing and element-type APIs, then compare them with the requested mixed-supertype, key-field, and type-filter operations; done means a decided API and working behavior for all examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.