ModularM
Modular2y ago
13 replies
benny

Type independent traits

Any ways to make the example code work? Would be nice to be able to implement custom traits for abstract classes

trait Container:
    fn __contains__(self, item: AnyType) -> Bool:
        ...


@value
struct List(Container):
    var data: VariadicList[Int]

    fn __contains__(self, item: Int) -> Bool:
        for i in self.data:
            if i == item:
                return True
        return False
Was this page helpful?