text icon indicating copy to clipboard operation
text copied to clipboard

headMaybe

Open domenkozar opened this issue 3 years ago • 4 comments

head is partial, so it would be great to have a safe alternative.

domenkozar avatar Mar 20 '21 11:03 domenkozar

https://hackage.haskell.org/package/text-1.2.4.1/docs/Data-Text.html#v:uncons ?

phadej avatar Mar 20 '21 13:03 phadej

I'd be in favor of adding the headMaybe function to have API-parity with other collections (though, tbh, I'd much prefer for head to return a Maybe Char).

parsonsmatt avatar Mar 20 '21 18:03 parsonsmatt

I'm also for making head return Maybe Char, although that will probably breaks lots of packages.

I was searching for Text -> Maybe Char so I didn't find it and used a workaround. I'm probably not the first nor the last.

domenkozar avatar Mar 20 '21 18:03 domenkozar

uncons is a natural way to eliminate strings, blessed by base. I'm not sure that an additional entity for a combination of uncons and fst is justified.

I'd be in favor of adding the headMaybe function to have API-parity with other collections

It will actually introduce API disparity with other collections. The only other package, which has such function, is rio.

though, tbh, I'd much prefer for head to return a Maybe Char

This is also not quite attested in other packages, and is a huge breaking change.

Bodigrim avatar Mar 20 '21 18:03 Bodigrim