Skip to content

Add functions to inspect individual Indexable values #25

@adamgundry

Description

@adamgundry

Given a single value of an Indexable type, it is possible to project out the values of any particular index for which IsIndexOf holds. However I can't figure out a way to do this very directly given the current API. The best I've been able to come up with is constructing and then consuming an IxSet, like this:

project :: forall ixs ix a . (IxSet.Indexable ixs a, IxSet.IsIndexOf ix ixs) => a -> [ix]
project a = map fst (IxSet.groupBy (IxSet.fromList @ixs [a]))

matches :: forall ixs ix a . (IxSet.Indexable ixs a, IxSet.IsIndexOf ix ixs) => [ix] -> a -> Bool
matches vs a = not $ IxSet.null (IxSet.fromList @ixs [a] IxSet.@+ vs)

It would be nice if ixset-typed exposed either these functions, or enough internals to make it possible to implement them. (At the moment there are quite a few things defined in Data.IxSet.Typed but not exported. Perhaps it is worth making a Data.IxSet.Typed.Internal module so the full definitions are accessible if needed?)

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