0

I ran into something that threw me off today. I was trying to define a function equivalent to Data.Text.commonPrefixes that throws away everything but the prefix.

The following works:

commonPrefix :: Text -> Text -> Maybe Text
commonPrefix a b = fmap firstTriple $ Text.commonPrefixes a b

firstTriple :: (a, b, c) -> a
firstTriple (a, _, _) = a

I originally tried doing it like this, which doesn't work:

commonPrefix :: Text -> Text -> Maybe Text
commonPrefix = fmap firstTriple . Text.commonPrefixes

Is there a way to define this function as a composition?

Sean Clark Hess
  • 15,859
  • 12
  • 52
  • 100

0 Answers0