6 people like it.

Lazy String

Lazy string based on seq

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
module LazyString = 
    type LazyString = char seq 

    let fromString (s:string) : LazyString = seq { for i in s do yield i }
    let toString (l:LazyString) = new string(Seq.toArray l)
    let concat (a:LazyString) (b:LazyString) : LazyString = Seq.concat [b;a]
    
    let replace (what:LazyString) (from:LazyString) (src:LazyString) : LazyString = 
        seq {
            for i in (src |> toString).Replace(what |> toString, from |> toString) do
                yield i
        }
    
    let substr (startIndex:int) (src:LazyString) : LazyString = 
        src |> Seq.skip (startIndex+1)

    let substring (startIndex:int) (count:int) (src:LazyString) : LazyString = 
        src |> Seq.skip (startIndex+1) |> Seq.take count

    //TODO: Implement other standard string operations

LazyString.fromString "Hello "
|> LazyString.concat (LazyString.fromString "C# world")
|> LazyString.replace (LazyString.fromString "C#") (LazyString.fromString "F#")
|> LazyString.toString
|> printfn "%s"
type LazyString = seq<char>

Full name: Script.LazyString.LazyString
Multiple items
val char : value:'T -> char (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.char

--------------------
type char = System.Char

Full name: Microsoft.FSharp.Core.char
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
val fromString : s:string -> LazyString

Full name: Script.LazyString.fromString
val s : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val i : char
val toString : l:LazyString -> string

Full name: Script.LazyString.toString
val l : LazyString
module Seq

from Microsoft.FSharp.Collections
val toArray : source:seq<'T> -> 'T []

Full name: Microsoft.FSharp.Collections.Seq.toArray
val concat : a:LazyString -> b:LazyString -> LazyString

Full name: Script.LazyString.concat
val a : LazyString
val b : LazyString
val concat : sources:seq<#seq<'T>> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.concat
val replace : what:LazyString -> from:LazyString -> src:LazyString -> LazyString

Full name: Script.LazyString.replace
val what : LazyString
val from : LazyString
val src : LazyString
val substr : startIndex:int -> src:LazyString -> LazyString

Full name: Script.LazyString.substr
val startIndex : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val skip : count:int -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.skip
val substring : startIndex:int -> count:int -> src:LazyString -> LazyString

Full name: Script.LazyString.substring
val count : int
val take : count:int -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.take
module LazyString

from Script
val fromString : s:string -> LazyString.LazyString

Full name: Script.LazyString.fromString
val concat : a:LazyString.LazyString -> b:LazyString.LazyString -> LazyString.LazyString

Full name: Script.LazyString.concat
val replace : what:LazyString.LazyString -> from:LazyString.LazyString -> src:LazyString.LazyString -> LazyString.LazyString

Full name: Script.LazyString.replace
val toString : l:LazyString.LazyString -> string

Full name: Script.LazyString.toString
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view Test code New version

More information

Link:http://fssnip.net/4k
Posted:13 years ago
Author:Ankur Dhama
Tags: lazy , sequences