Last active
February 9, 2023 23:14
-
-
Save ruxo/9b79350eb2676bad1fb5 to your computer and use it in GitHub Desktop.
F# String Reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type StrRef = | |
| { str: string | |
| start: int | |
| length: int } | |
| [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] | |
| module StrRef = | |
| let substring n s = { s with length=(min s.length n) } | |
| let lastPos sr = sr.start + sr.length - 1 | |
| let iterate sr = | |
| seq { | |
| for i = sr.start to (lastPos sr) do | |
| yield sr.str.[i] | |
| } | |
| let equals (s: string) sr = s.Length = sr.length && (Seq.forall id ((=) <!> iterate sr <*> s)) | |
| let skip n sr = { sr with start = (min (lastPos sr) (sr.start+n)) | |
| length= (max 0 (sr.length - n))} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment