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]()
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.
3 Replies
Jack Clayton
Jack Clayton15mo ago
Thanks for the feedback @TeamPuzel I agree! Can you raise a discussion on GitHub here: https://github.com/modularml/mojo/discussions/new?category=ideas
TeamPuzel
TeamPuzelOP15mo ago
Of course, I now moved this to discussions.
Jack Clayton
Jack Clayton15mo ago
Awesome thanks! link here for anyone asking the same question: https://github.com/modularml/mojo/discussions/678
GitHub
coerce fn() to fn() capturing · modularml mojo · Discussion #678
When writing a List implementation this became a problem for functions like map filter or fold: fn first(self, where: fn(T) -> Bool) -> Maybe[T]: for item in self: if where(item): return item...
Want results from more Discord servers?
Add your server