ModularM
Modular3y ago
3 replies
TeamPuzel

Why doesn't fn() coerce to fn() capturing

This works thanks to the signatures being different:
fn first(self, where: fn(T) -> Bool) -> Optional[T]:
    for item in self:
        if where(item): return item
    return Optional[T]()
    
fn first(self, where: fn(T) capturing -> Bool) -> Optional[T]:
    for item in self:
        if where(item): return item
    return Optional[T]()

However it's still annoying to duplicate every function twice.
Was this page helpful?