Coding 2023-03-23

Tags:
By Max Woerner Chase

All right, let's move through more parametric stuff...

The next function defines a helper, which I'd like to move into the helper module related to "parametric maps". Basically, I want a few different example magma functions, and one of them will be "bail if the values don't match". All together, this should result in something like:

def combine(self, other: Metadata) -> Metadata:
    return Metadata(
        box_labels=self.box_labels | other.box_labels, # I, uh, missed adding this to the other constructors.
        selection_labels=self.selection_labels | other.selection_labels,
        iterated_labels=self.iterated_labels | other.iterated_labels,
        exclusive_labels=self.exclusive_labels | other.exclusive_labels,
        multivalue_labels=self.multivalue_labels & other.multivalue_labels,
        input=self.input.update_with(
            _per_item_parametric_mapping.reject_if_different, other.input
        ),
    )

The next function is... not named well... Let's change it to...

def iterated_labels_except_for(
    self, labels: _selection.Labels
) -> _selection.Labels:
    if not labels <= self.iterated_labels:
        raise ValueError
    return self.iterated_labels.difference(labels)

And now, the last bits of code for the Metadata class:

@property
def singleton_labels(self) -> _selection.Labels:
    return (
        (self.exclusive_labels - self.iterated_labels)
        | (self.selection_labels - self.multivalue_labels)
    )

def selections(
    self, box: _box.Box
) -> typing.Iterator[_selection.Selection]:
    for box_label in self.box_labels:
        if box_label not in box:
            raise ValueError
    # Maybe check that every selection label maps to a non-empty value?
    for singleton_label in self.singleton_labels:
        value = box[singleton_label]
        if len(value) > 1:
            raise ValueError
    return _selection.selections(self.iterated_labels, box)

Let's see, the next really interesting one is "include_box", which. Hm. That should fail if the included box has a non-empty intersection with selection_labels, and it should set box_labels to the difference.

I think that all gets me to a good place with the parametric module. If the rest of the code has a problem with the changes I'm proposing, then that, um... that's a problem with the code that's not in the module, frankly.

Now, I'm going to take a break from working on this for a day or so, then get into either this or the common motrfile concept. In the meantime, I'm going to get in some work on the draft for my writing.

For now, it's too late again, and I need to get to bed.

Good night.