From 0cc05f9d23569c20352c1a29208a5dd3ab0e51f1 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 16:24:45 +0300 Subject: [PATCH 1/6] Sorted the string.fsi entries and added examples to each one --- src/fsharp/FSharp.Core/string.fsi | 232 ++++++++++++++++++++++-------- 1 file changed, 172 insertions(+), 60 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index cca1054f58a..62d8c86296b 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -18,6 +18,29 @@ namespace Microsoft.FSharp.Core [] module String = + /// Builds a new string whose characters are the results of applying the function mapping + /// to each of the characters of the input string and concatenating the resulting + /// strings. + /// + /// The function to produce a string from each character of the input string. + /// The input string. + /// + /// The concatenated string. + /// + /// The following samples shows how to interspace spaces in a text + /// + /// String.collect (sprintf "%c ") "Stefan says: Hi!" // evaluates "S t e f a n s a y s : H i ! " + /// + /// + /// + /// How to show the ASCII representation of a very secret text: + /// + /// String.collect (fun chr -> int chr |> sprintf "%d ") "Secret" // evaluates "83 101 99 114 101 116 " + /// + /// + [] + val collect: mapping:(char -> string) -> str:string -> string + /// Returns a new string made by concatenating the given strings /// with separator sep, that is a1 + sep + ... + sep + aN. /// The separator string to be inserted between the strings @@ -27,54 +50,32 @@ namespace Microsoft.FSharp.Core /// A new string consisting of the concatenated strings separated by /// the separation string. /// Thrown when strings is null. + /// + /// + /// + /// String.concat " " ["Stefan"; "says:"; "Hello"; "there!"] // evaluates "Stefan says: Hello there!" + /// [0..9] |> List.map string |> String.concat "" // evaluates "0123456789" + /// String.concat "!" ["No exclamation point here"] // evaluates "No exclamation point here" + /// + /// [] val concat: sep:string -> strings: seq -> string - /// Applies the function action to each character in the string. - /// - /// The function to be applied to each character of the string. - /// The input string. - [] - val iter: action:(char -> unit) -> str:string -> unit - - /// Applies the function action to the index of each character in the string and the - /// character itself. - /// - /// The function to apply to each character and index of the string. - /// The input string. - [] - val iteri: action:(int -> char -> unit) -> str:string -> unit - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each of the characters of the input string. - /// - /// The function to apply to the characters of the string. - /// The input string. - /// - /// The resulting string. - [] - val map: mapping:(char -> char) -> str:string -> string - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each character and index of the input string. - /// - /// The function to apply to each character and index of the string. - /// The input string. - /// - /// The resulting string. - [] - val mapi: mapping:(int -> char -> char) -> str:string -> string - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each of the characters of the input string and concatenating the resulting - /// strings. + /// Tests if any character of the string satisfies the given predicate. /// - /// The function to produce a string from each character of the input string. + /// The function to test each character of the string. /// The input string. /// - /// The concatenated string. - [] - val collect: mapping:(char -> string) -> str:string -> string + /// True if any character returns true for the predicate and false otherwise. + /// + /// Looking for uppercase characters + /// + /// String.exists System.Char.IsUpper "Yoda" // evaluates true + /// String.exists System.Char.IsUpper "nope" // evaluates false + /// + /// + [] + val exists: predicate:(char -> bool) -> str:string -> bool /// Builds a new string containing only the characters of the input string /// for which the given predicate returns "true". @@ -85,9 +86,32 @@ namespace Microsoft.FSharp.Core /// The input string. /// /// The resulting string. + /// + /// Filtering out just alphanumeric characters or just digits + /// + /// String.filter System.Uri.IsHexDigit "0 1 2 3 4 5 6 7 8 9 a A m M" // evaluates "123456789aA" + /// String.filter System.Char.IsDigit "hello" // evaluates "" + /// + /// [] val filter: predicate:(char -> bool) -> str:string -> string + /// Tests if all characters in the string satisfy the given predicate. + /// + /// The function to test each character of the string. + /// The input string. + /// + /// True if all characters return true for the predicate and false otherwise. + /// + /// Looking for lowercase characters + /// + /// String.forall System.Char.IsLower "all are lower" // evaluates false + /// String.forall System.Char.IsLower "allarelower" // evaluates true + /// + /// + [] + val forall: predicate:(char -> bool) -> str:string -> bool + /// Builds a new string whose characters are the results of applying the function mapping /// to each index from 0 to count-1 and concatenating the resulting /// strings. @@ -98,26 +122,115 @@ namespace Microsoft.FSharp.Core /// /// The constructed string. /// Thrown when count is negative. + /// + /// Enumerate digits ASCII codes + /// + /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " + /// + /// [] val init: count:int -> initializer:(int -> string) -> string - /// Tests if all characters in the string satisfy the given predicate. + /// Applies the function action to each character in the string. /// - /// The function to test each character of the string. + /// The function to be applied to each character of the string. /// The input string. + /// + /// + /// + /// String.iter (fun c -> printfn "%c %d" c (int c)) "Hello" + /// // evaluates unit + /// // prints: + /// H 72 + /// e 101 + /// l 108 + /// l 108 + /// o 111 + /// + /// + [] + val iter: action:(char -> unit) -> str:string -> unit + + /// Applies the function action to the index of each character in the string and the + /// character itself. /// - /// True if all characters return true for the predicate and false otherwise. - [] - val forall: predicate:(char -> bool) -> str:string -> bool + /// The function to apply to each character and index of the string. + /// The input string. + /// + /// + /// + /// String.length null // evaluates 0 + /// String.length "" // evaluates 0 + /// String.length "123" // evaluates 3 + /// + /// + /// + /// + /// + /// String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) "Hello" + /// // evaluates unit + /// // prints: + /// 1. H 72 + /// 2. e 101 + /// 3. l 108 + /// 4. l 108 + /// 5. o 111 + /// + /// + [] + val iteri: action:(int -> char -> unit) -> str:string -> unit - /// Tests if any character of the string satisfies the given predicate. + /// Returns the length of the string. /// - /// The function to test each character of the string. /// The input string. /// - /// True if any character returns true for the predicate and false otherwise. - [] - val exists: predicate:(char -> bool) -> str:string -> bool + /// The number of characters in the string. + /// + /// + /// + /// String.length null // evaluates 0 + /// String.length "" // evaluates 0 + /// String.length "123" // evaluates 3 + /// + /// + [] + val length: str:string -> int + + /// Builds a new string whose characters are the results of applying the function mapping + /// to each of the characters of the input string. + /// + /// The function to apply to the characters of the string. + /// The input string. + /// + /// The resulting string. + /// + /// Changing case to upper for all characters in the input string + /// + /// String.map System.Char.ToUpper "Hello there!" // evaluates "HELLO THERE!" + /// + /// + [] + val map: mapping:(char -> char) -> str:string -> string + + /// Builds a new string whose characters are the results of applying the function mapping + /// to each character and index of the input string. + /// + /// The function to apply to each character and index of the string. + /// The input string. + /// + /// The resulting string. + /// + /// Alternating case for all characters in the input string + /// + /// let alternateCase indx chr = + /// if 0 = indx % 2 + /// then System.Char.ToUpper chr + /// else System.Char.ToLower chr + /// String.mapi alternateCase "Hello there!" // evaluates "HeLlO ThErE!" + /// + /// + [] + val mapi: mapping:(int -> char -> char) -> str:string -> string /// Returns a string by concatenating count instances of str. /// @@ -126,14 +239,13 @@ namespace Microsoft.FSharp.Core /// /// The concatenated string. /// Thrown when count is negative. + /// + /// + /// + /// String.replicate 3 "Do it! " // evaluates "Do it! Do it! Do it! " + /// + /// [] val replicate: count:int -> str: string -> string - - /// Returns the length of the string. - /// - /// The input string. - /// - /// The number of characters in the string. - [] - val length: str:string -> int + From 918673f8b78ed122f8d0ca3e1792ff79bbf16f97 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 18:08:32 +0300 Subject: [PATCH 2/6] Applying suggestions to the String examples --- src/fsharp/FSharp.Core/string.fsi | 99 +++++++++++++++++++------------ 1 file changed, 60 insertions(+), 39 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 62d8c86296b..6cd6683da9f 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -27,15 +27,16 @@ namespace Microsoft.FSharp.Core /// /// The concatenated string. /// - /// The following samples shows how to interspace spaces in a text + /// The following samples shows how to interspace spaces in a text /// - /// String.collect (sprintf "%c ") "Stefan says: Hi!" // evaluates "S t e f a n s a y s : H i ! " + /// let input = "Stefan says: Hi!" + /// input |> String.collect (sprintf "%c ") // evaluates "S t e f a n s a y s : H i ! " /// /// /// - /// How to show the ASCII representation of a very secret text: + /// How to show the ASCII representation of a very secret text /// - /// String.collect (fun chr -> int chr |> sprintf "%d ") "Secret" // evaluates "83 101 99 114 101 116 " + /// "Secret" |> String.collect (fun chr -> int chr |> sprintf "%d ") // evaluates "83 101 99 114 101 116 " /// /// [] @@ -51,11 +52,16 @@ namespace Microsoft.FSharp.Core /// the separation string. /// Thrown when strings is null. /// - /// + /// /// - /// String.concat " " ["Stefan"; "says:"; "Hello"; "there!"] // evaluates "Stefan says: Hello there!" - /// [0..9] |> List.map string |> String.concat "" // evaluates "0123456789" - /// String.concat "!" ["No exclamation point here"] // evaluates "No exclamation point here" + /// let input1 = ["Stefan"; "says:"; "Hello"; "there!"] + /// input1 |> String.concat " " // evaluates "Stefan says: Hello there!" + /// + /// let input2 = [0..9] |> List.map string + /// input2 |> String.concat "" // evaluates "0123456789" + /// + /// let input3 = ["No exclamation point here"] + /// input3 |> String.concat "!" // evaluates "No exclamation point here" /// /// [] @@ -68,10 +74,13 @@ namespace Microsoft.FSharp.Core /// /// True if any character returns true for the predicate and false otherwise. /// - /// Looking for uppercase characters + /// Looking for uppercase characters /// - /// String.exists System.Char.IsUpper "Yoda" // evaluates true - /// String.exists System.Char.IsUpper "nope" // evaluates false + /// open System + /// + /// "Yoda" |> String.exists Char.IsUpper // evaluates true + /// + /// "nope" |> String.exists Char.IsUpper // evaluates false /// /// [] @@ -87,10 +96,19 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Filtering out just alphanumeric characters or just digits + /// Filtering out just alphanumeric characters + /// + /// open System + /// + /// let input = "0 1 2 3 4 5 6 7 8 9 a A m M" + /// input |> String.filter Uri.IsHexDigit // evaluates "123456789aA" + /// + /// + /// Filtering out just digits /// - /// String.filter System.Uri.IsHexDigit "0 1 2 3 4 5 6 7 8 9 a A m M" // evaluates "123456789aA" - /// String.filter System.Char.IsDigit "hello" // evaluates "" + /// open System + /// + /// "hello" |> String.filter Char.IsDigit // evaluates "" /// /// [] @@ -103,10 +121,13 @@ namespace Microsoft.FSharp.Core /// /// True if all characters return true for the predicate and false otherwise. /// - /// Looking for lowercase characters + /// Looking for lowercase characters /// - /// String.forall System.Char.IsLower "all are lower" // evaluates false - /// String.forall System.Char.IsLower "allarelower" // evaluates true + /// open System + /// + /// "all are lower" |> String.forall Char.IsLower // evaluates false + /// + /// "allarelower" |> String.forall Char.IsLower // evaluates true /// /// [] @@ -123,7 +144,7 @@ namespace Microsoft.FSharp.Core /// The constructed string. /// Thrown when count is negative. /// - /// Enumerate digits ASCII codes + /// Enumerate digits ASCII codes /// /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " /// @@ -136,9 +157,10 @@ namespace Microsoft.FSharp.Core /// The function to be applied to each character of the string. /// The input string. /// - /// + /// Printing the ASCII code for each characater in the string /// - /// String.iter (fun c -> printfn "%c %d" c (int c)) "Hello" + /// let input = "Hello" + /// input |> String.iter (fun c -> printfn "%c %d" c (int c)) /// // evaluates unit /// // prints: /// H 72 @@ -157,17 +179,11 @@ namespace Microsoft.FSharp.Core /// The function to apply to each character and index of the string. /// The input string. /// - /// + /// Numbering the characters and printing the associated ASCII code + /// for each characater in the input string /// - /// String.length null // evaluates 0 - /// String.length "" // evaluates 0 - /// String.length "123" // evaluates 3 - /// - /// - /// - /// - /// - /// String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) "Hello" + /// let input = "Hello" + /// input |> String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) /// // evaluates unit /// // prints: /// 1. H 72 @@ -186,7 +202,7 @@ namespace Microsoft.FSharp.Core /// /// The number of characters in the string. /// - /// + /// Getting the length of different strings /// /// String.length null // evaluates 0 /// String.length "" // evaluates 0 @@ -204,9 +220,11 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Changing case to upper for all characters in the input string + /// Changing case to upper for all characters in the input string /// - /// String.map System.Char.ToUpper "Hello there!" // evaluates "HELLO THERE!" + /// open System + /// let input = "Hello there!" + /// input |> String.map Char.ToUpper // evaluates "HELLO THERE!" /// /// [] @@ -220,13 +238,16 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Alternating case for all characters in the input string + /// Alternating case for all characters in the input string /// + /// open System + /// /// let alternateCase indx chr = /// if 0 = indx % 2 - /// then System.Char.ToUpper chr - /// else System.Char.ToLower chr - /// String.mapi alternateCase "Hello there!" // evaluates "HeLlO ThErE!" + /// then Char.ToUpper chr + /// else Char.ToLower chr + /// let input = "Hello there!" + /// input |> String.mapi alternateCase // evaluates "HeLlO ThErE!" /// /// [] @@ -240,9 +261,9 @@ namespace Microsoft.FSharp.Core /// The concatenated string. /// Thrown when count is negative. /// - /// + /// /// - /// String.replicate 3 "Do it! " // evaluates "Do it! Do it! Do it! " + /// "Do it!" |> String.replicate 3 // evaluates "Do it!Do it!Do it!" /// /// [] From 1f4e7900629f45fc3858631d2192e9dd2e237cb9 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 19:14:00 +0300 Subject: [PATCH 3/6] Following the suggestion that is more clear. --- src/fsharp/FSharp.Core/string.fsi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 6cd6683da9f..73174bc6bbd 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -58,10 +58,11 @@ namespace Microsoft.FSharp.Core /// input1 |> String.concat " " // evaluates "Stefan says: Hello there!" /// /// let input2 = [0..9] |> List.map string - /// input2 |> String.concat "" // evaluates "0123456789" + /// input2 |> String.concat "" // evaluates "0123456789" + /// input2 |> String.concat ", " // evaluates "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" /// - /// let input3 = ["No exclamation point here"] - /// input3 |> String.concat "!" // evaluates "No exclamation point here" + /// let input3 = ["No comma"] + /// input3 |> String.concat "," // evaluates "No comma" /// /// [] From 36935c9c88d5da0e7d92a03785cc872e65fae258 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 16:24:45 +0300 Subject: [PATCH 4/6] Sorted the string.fsi entries and added examples to each one --- src/fsharp/FSharp.Core/string.fsi | 232 ++++++++++++++++++++++-------- 1 file changed, 172 insertions(+), 60 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index cca1054f58a..62d8c86296b 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -18,6 +18,29 @@ namespace Microsoft.FSharp.Core [] module String = + /// Builds a new string whose characters are the results of applying the function mapping + /// to each of the characters of the input string and concatenating the resulting + /// strings. + /// + /// The function to produce a string from each character of the input string. + /// The input string. + /// + /// The concatenated string. + /// + /// The following samples shows how to interspace spaces in a text + /// + /// String.collect (sprintf "%c ") "Stefan says: Hi!" // evaluates "S t e f a n s a y s : H i ! " + /// + /// + /// + /// How to show the ASCII representation of a very secret text: + /// + /// String.collect (fun chr -> int chr |> sprintf "%d ") "Secret" // evaluates "83 101 99 114 101 116 " + /// + /// + [] + val collect: mapping:(char -> string) -> str:string -> string + /// Returns a new string made by concatenating the given strings /// with separator sep, that is a1 + sep + ... + sep + aN. /// The separator string to be inserted between the strings @@ -27,54 +50,32 @@ namespace Microsoft.FSharp.Core /// A new string consisting of the concatenated strings separated by /// the separation string. /// Thrown when strings is null. + /// + /// + /// + /// String.concat " " ["Stefan"; "says:"; "Hello"; "there!"] // evaluates "Stefan says: Hello there!" + /// [0..9] |> List.map string |> String.concat "" // evaluates "0123456789" + /// String.concat "!" ["No exclamation point here"] // evaluates "No exclamation point here" + /// + /// [] val concat: sep:string -> strings: seq -> string - /// Applies the function action to each character in the string. - /// - /// The function to be applied to each character of the string. - /// The input string. - [] - val iter: action:(char -> unit) -> str:string -> unit - - /// Applies the function action to the index of each character in the string and the - /// character itself. - /// - /// The function to apply to each character and index of the string. - /// The input string. - [] - val iteri: action:(int -> char -> unit) -> str:string -> unit - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each of the characters of the input string. - /// - /// The function to apply to the characters of the string. - /// The input string. - /// - /// The resulting string. - [] - val map: mapping:(char -> char) -> str:string -> string - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each character and index of the input string. - /// - /// The function to apply to each character and index of the string. - /// The input string. - /// - /// The resulting string. - [] - val mapi: mapping:(int -> char -> char) -> str:string -> string - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each of the characters of the input string and concatenating the resulting - /// strings. + /// Tests if any character of the string satisfies the given predicate. /// - /// The function to produce a string from each character of the input string. + /// The function to test each character of the string. /// The input string. /// - /// The concatenated string. - [] - val collect: mapping:(char -> string) -> str:string -> string + /// True if any character returns true for the predicate and false otherwise. + /// + /// Looking for uppercase characters + /// + /// String.exists System.Char.IsUpper "Yoda" // evaluates true + /// String.exists System.Char.IsUpper "nope" // evaluates false + /// + /// + [] + val exists: predicate:(char -> bool) -> str:string -> bool /// Builds a new string containing only the characters of the input string /// for which the given predicate returns "true". @@ -85,9 +86,32 @@ namespace Microsoft.FSharp.Core /// The input string. /// /// The resulting string. + /// + /// Filtering out just alphanumeric characters or just digits + /// + /// String.filter System.Uri.IsHexDigit "0 1 2 3 4 5 6 7 8 9 a A m M" // evaluates "123456789aA" + /// String.filter System.Char.IsDigit "hello" // evaluates "" + /// + /// [] val filter: predicate:(char -> bool) -> str:string -> string + /// Tests if all characters in the string satisfy the given predicate. + /// + /// The function to test each character of the string. + /// The input string. + /// + /// True if all characters return true for the predicate and false otherwise. + /// + /// Looking for lowercase characters + /// + /// String.forall System.Char.IsLower "all are lower" // evaluates false + /// String.forall System.Char.IsLower "allarelower" // evaluates true + /// + /// + [] + val forall: predicate:(char -> bool) -> str:string -> bool + /// Builds a new string whose characters are the results of applying the function mapping /// to each index from 0 to count-1 and concatenating the resulting /// strings. @@ -98,26 +122,115 @@ namespace Microsoft.FSharp.Core /// /// The constructed string. /// Thrown when count is negative. + /// + /// Enumerate digits ASCII codes + /// + /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " + /// + /// [] val init: count:int -> initializer:(int -> string) -> string - /// Tests if all characters in the string satisfy the given predicate. + /// Applies the function action to each character in the string. /// - /// The function to test each character of the string. + /// The function to be applied to each character of the string. /// The input string. + /// + /// + /// + /// String.iter (fun c -> printfn "%c %d" c (int c)) "Hello" + /// // evaluates unit + /// // prints: + /// H 72 + /// e 101 + /// l 108 + /// l 108 + /// o 111 + /// + /// + [] + val iter: action:(char -> unit) -> str:string -> unit + + /// Applies the function action to the index of each character in the string and the + /// character itself. /// - /// True if all characters return true for the predicate and false otherwise. - [] - val forall: predicate:(char -> bool) -> str:string -> bool + /// The function to apply to each character and index of the string. + /// The input string. + /// + /// + /// + /// String.length null // evaluates 0 + /// String.length "" // evaluates 0 + /// String.length "123" // evaluates 3 + /// + /// + /// + /// + /// + /// String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) "Hello" + /// // evaluates unit + /// // prints: + /// 1. H 72 + /// 2. e 101 + /// 3. l 108 + /// 4. l 108 + /// 5. o 111 + /// + /// + [] + val iteri: action:(int -> char -> unit) -> str:string -> unit - /// Tests if any character of the string satisfies the given predicate. + /// Returns the length of the string. /// - /// The function to test each character of the string. /// The input string. /// - /// True if any character returns true for the predicate and false otherwise. - [] - val exists: predicate:(char -> bool) -> str:string -> bool + /// The number of characters in the string. + /// + /// + /// + /// String.length null // evaluates 0 + /// String.length "" // evaluates 0 + /// String.length "123" // evaluates 3 + /// + /// + [] + val length: str:string -> int + + /// Builds a new string whose characters are the results of applying the function mapping + /// to each of the characters of the input string. + /// + /// The function to apply to the characters of the string. + /// The input string. + /// + /// The resulting string. + /// + /// Changing case to upper for all characters in the input string + /// + /// String.map System.Char.ToUpper "Hello there!" // evaluates "HELLO THERE!" + /// + /// + [] + val map: mapping:(char -> char) -> str:string -> string + + /// Builds a new string whose characters are the results of applying the function mapping + /// to each character and index of the input string. + /// + /// The function to apply to each character and index of the string. + /// The input string. + /// + /// The resulting string. + /// + /// Alternating case for all characters in the input string + /// + /// let alternateCase indx chr = + /// if 0 = indx % 2 + /// then System.Char.ToUpper chr + /// else System.Char.ToLower chr + /// String.mapi alternateCase "Hello there!" // evaluates "HeLlO ThErE!" + /// + /// + [] + val mapi: mapping:(int -> char -> char) -> str:string -> string /// Returns a string by concatenating count instances of str. /// @@ -126,14 +239,13 @@ namespace Microsoft.FSharp.Core /// /// The concatenated string. /// Thrown when count is negative. + /// + /// + /// + /// String.replicate 3 "Do it! " // evaluates "Do it! Do it! Do it! " + /// + /// [] val replicate: count:int -> str: string -> string - - /// Returns the length of the string. - /// - /// The input string. - /// - /// The number of characters in the string. - [] - val length: str:string -> int + From 712f32fdb1c8dad42300f0a583bd436c8d132da2 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 18:08:32 +0300 Subject: [PATCH 5/6] Applying suggestions to the String examples --- src/fsharp/FSharp.Core/string.fsi | 99 +++++++++++++++++++------------ 1 file changed, 60 insertions(+), 39 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 62d8c86296b..6cd6683da9f 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -27,15 +27,16 @@ namespace Microsoft.FSharp.Core /// /// The concatenated string. /// - /// The following samples shows how to interspace spaces in a text + /// The following samples shows how to interspace spaces in a text /// - /// String.collect (sprintf "%c ") "Stefan says: Hi!" // evaluates "S t e f a n s a y s : H i ! " + /// let input = "Stefan says: Hi!" + /// input |> String.collect (sprintf "%c ") // evaluates "S t e f a n s a y s : H i ! " /// /// /// - /// How to show the ASCII representation of a very secret text: + /// How to show the ASCII representation of a very secret text /// - /// String.collect (fun chr -> int chr |> sprintf "%d ") "Secret" // evaluates "83 101 99 114 101 116 " + /// "Secret" |> String.collect (fun chr -> int chr |> sprintf "%d ") // evaluates "83 101 99 114 101 116 " /// /// [] @@ -51,11 +52,16 @@ namespace Microsoft.FSharp.Core /// the separation string. /// Thrown when strings is null. /// - /// + /// /// - /// String.concat " " ["Stefan"; "says:"; "Hello"; "there!"] // evaluates "Stefan says: Hello there!" - /// [0..9] |> List.map string |> String.concat "" // evaluates "0123456789" - /// String.concat "!" ["No exclamation point here"] // evaluates "No exclamation point here" + /// let input1 = ["Stefan"; "says:"; "Hello"; "there!"] + /// input1 |> String.concat " " // evaluates "Stefan says: Hello there!" + /// + /// let input2 = [0..9] |> List.map string + /// input2 |> String.concat "" // evaluates "0123456789" + /// + /// let input3 = ["No exclamation point here"] + /// input3 |> String.concat "!" // evaluates "No exclamation point here" /// /// [] @@ -68,10 +74,13 @@ namespace Microsoft.FSharp.Core /// /// True if any character returns true for the predicate and false otherwise. /// - /// Looking for uppercase characters + /// Looking for uppercase characters /// - /// String.exists System.Char.IsUpper "Yoda" // evaluates true - /// String.exists System.Char.IsUpper "nope" // evaluates false + /// open System + /// + /// "Yoda" |> String.exists Char.IsUpper // evaluates true + /// + /// "nope" |> String.exists Char.IsUpper // evaluates false /// /// [] @@ -87,10 +96,19 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Filtering out just alphanumeric characters or just digits + /// Filtering out just alphanumeric characters + /// + /// open System + /// + /// let input = "0 1 2 3 4 5 6 7 8 9 a A m M" + /// input |> String.filter Uri.IsHexDigit // evaluates "123456789aA" + /// + /// + /// Filtering out just digits /// - /// String.filter System.Uri.IsHexDigit "0 1 2 3 4 5 6 7 8 9 a A m M" // evaluates "123456789aA" - /// String.filter System.Char.IsDigit "hello" // evaluates "" + /// open System + /// + /// "hello" |> String.filter Char.IsDigit // evaluates "" /// /// [] @@ -103,10 +121,13 @@ namespace Microsoft.FSharp.Core /// /// True if all characters return true for the predicate and false otherwise. /// - /// Looking for lowercase characters + /// Looking for lowercase characters /// - /// String.forall System.Char.IsLower "all are lower" // evaluates false - /// String.forall System.Char.IsLower "allarelower" // evaluates true + /// open System + /// + /// "all are lower" |> String.forall Char.IsLower // evaluates false + /// + /// "allarelower" |> String.forall Char.IsLower // evaluates true /// /// [] @@ -123,7 +144,7 @@ namespace Microsoft.FSharp.Core /// The constructed string. /// Thrown when count is negative. /// - /// Enumerate digits ASCII codes + /// Enumerate digits ASCII codes /// /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " /// @@ -136,9 +157,10 @@ namespace Microsoft.FSharp.Core /// The function to be applied to each character of the string. /// The input string. /// - /// + /// Printing the ASCII code for each characater in the string /// - /// String.iter (fun c -> printfn "%c %d" c (int c)) "Hello" + /// let input = "Hello" + /// input |> String.iter (fun c -> printfn "%c %d" c (int c)) /// // evaluates unit /// // prints: /// H 72 @@ -157,17 +179,11 @@ namespace Microsoft.FSharp.Core /// The function to apply to each character and index of the string. /// The input string. /// - /// + /// Numbering the characters and printing the associated ASCII code + /// for each characater in the input string /// - /// String.length null // evaluates 0 - /// String.length "" // evaluates 0 - /// String.length "123" // evaluates 3 - /// - /// - /// - /// - /// - /// String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) "Hello" + /// let input = "Hello" + /// input |> String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) /// // evaluates unit /// // prints: /// 1. H 72 @@ -186,7 +202,7 @@ namespace Microsoft.FSharp.Core /// /// The number of characters in the string. /// - /// + /// Getting the length of different strings /// /// String.length null // evaluates 0 /// String.length "" // evaluates 0 @@ -204,9 +220,11 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Changing case to upper for all characters in the input string + /// Changing case to upper for all characters in the input string /// - /// String.map System.Char.ToUpper "Hello there!" // evaluates "HELLO THERE!" + /// open System + /// let input = "Hello there!" + /// input |> String.map Char.ToUpper // evaluates "HELLO THERE!" /// /// [] @@ -220,13 +238,16 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Alternating case for all characters in the input string + /// Alternating case for all characters in the input string /// + /// open System + /// /// let alternateCase indx chr = /// if 0 = indx % 2 - /// then System.Char.ToUpper chr - /// else System.Char.ToLower chr - /// String.mapi alternateCase "Hello there!" // evaluates "HeLlO ThErE!" + /// then Char.ToUpper chr + /// else Char.ToLower chr + /// let input = "Hello there!" + /// input |> String.mapi alternateCase // evaluates "HeLlO ThErE!" /// /// [] @@ -240,9 +261,9 @@ namespace Microsoft.FSharp.Core /// The concatenated string. /// Thrown when count is negative. /// - /// + /// /// - /// String.replicate 3 "Do it! " // evaluates "Do it! Do it! Do it! " + /// "Do it!" |> String.replicate 3 // evaluates "Do it!Do it!Do it!" /// /// [] From 04dc5d62fb786bea8ca03b06ab3c1c767697bbd1 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 19:14:00 +0300 Subject: [PATCH 6/6] Following the suggestion that is more clear. --- src/fsharp/FSharp.Core/string.fsi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 6cd6683da9f..73174bc6bbd 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -58,10 +58,11 @@ namespace Microsoft.FSharp.Core /// input1 |> String.concat " " // evaluates "Stefan says: Hello there!" /// /// let input2 = [0..9] |> List.map string - /// input2 |> String.concat "" // evaluates "0123456789" + /// input2 |> String.concat "" // evaluates "0123456789" + /// input2 |> String.concat ", " // evaluates "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" /// - /// let input3 = ["No exclamation point here"] - /// input3 |> String.concat "!" // evaluates "No exclamation point here" + /// let input3 = ["No comma"] + /// input3 |> String.concat "," // evaluates "No comma" /// /// []