News for hackers. Stuff that matters.
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.

  heads :: [[a]] -> [a]
  heads xs = [y | (y:ys) <- xs]

  -- heads [[1],[],[2,3]] == [1,2]
Doing the above using maps and filters looks very different:

  heads' = map head . filter (not . null)
Python doesn't really support Haskell-like pattern matching, so the above doesn't apply.
Re:Why I'm still using Python by pdonis on Friday December 30, 2022 @04:56PM (#34190580)
> 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.

Re:Why I'm still using Python by ulucs on Friday December 30, 2022 @05:02PM (#34190616)
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
Re:Why I'm still using Python by ogogmad on Saturday December 31, 2022 @06:21AM (#34195436)
That doesn't look like a direct substitute that covers every case.