You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was surprised not to find a function in the library to split a text on the first match of a character/text/predicate, with the matched part discarded.
This is not difficult to write using breakOn and drop, but I think a function implemented with the internals of the library might have better performance.
split1::Char->Text-> (Text, Text)
split1 c = (id***drop1) . (breakOn $ singleton c)
IMHO split1 c = fmap (drop 1) . break (== c) is short enough and does not suffer from any significant performance penalty: drop 1 is constant-time, negligible in comparison to the linear time of break.
Note that the function from byteslice has a different signature, with Maybe.
I was surprised not to find a function in the library to split a text on the first match of a character/text/predicate, with the matched part discarded.
This is not difficult to write using
breakOn
anddrop
, but I think a function implemented with the internals of the library might have better performance.See a similar function (previously called
splitOnce
) in thebyteslice
package, and a question on Stack Overflow aboutsplitAtfirst
.The text was updated successfully, but these errors were encountered: