ModularM
Modular3y ago
2 replies
Henk-Jan Lebbink

How to implement the following simple comparison function

I would like to implement the following simple function, but I cannot find an alternative for AnyType (interface?) that defines comparison operators. In the following code a __ne__ is needed for ai != bi.

It's as if I'm missing a manual. If someone knows how to do this, or knows how to make me cope that is cannot be done...

fn equal_vector[T: AnyType](a: DynamicVector[T], b: DynamicVector[T]) -> Bool:
    # assumed a and b are sorted
    if a.__len__() != b.__len__():
        return False
    for i in range (a.__len__()):
        let ai: T = a.__getitem__(i)
        let bi: T = b.__getitem__(i)
        if ai != bi:  ## compilation error HERE
            return False
    return True
Was this page helpful?