Re:Why I'm still using Python
by ogogmad on Friday December 30, 2022 @03:51PM
(#34189928)
Being pedantic: This isn't true in Haskell, because list comprehensions can use pattern matching, while map+filter can't.
Doing the above using maps and filters looks very different:
Python doesn't really support Haskell-like pattern matching, so the above doesn't apply.
[ Parent
| on HN ]
> Python doesn't really support Haskell-like pattern matching
It does as of 3.10:
https://peps.python.org/pep-0622/
Not as sophisticated as what Haskell can do, I'm sure, but I think it's a good addition to Python.
The thing you're looking for is easily found with a Hoogle search for type
(a -> Maybe b) -> [a] -> [b]
Which yields mapMaybe: https://hackage.haskell.org/package/base-4.17.0.0/docs/Data-.... so you end up with heads = mapMaybe safeHead