O(n+m) Find the first instance of
needle (which must
be non-
null) in
haystack. The first element of the
returned tuple is the prefix of
haystack before
needle is matched. The second is the remainder of
haystack, starting with the match.
Examples:
breakOn "::" "a::b::c" ==> ("a", "::b::c")
breakOn "/" "foobar" ==> ("foobar", "")
Laws:
append prefix match == haystack
where (prefix, match) = breakOn needle haystack
If you need to break a string by a substring repeatedly (e.g. you want
to break on every instance of a substring), use
breakOnAll
instead, as it has lower startup overhead.
In (unlikely) bad cases, this function's time complexity degrades
towards
O(n*m).