Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6221ab5

Browse files
rojepplatkin
authored andcommitted
Implement String.filter
commit d70a2db98fe59a2f6674dd699725abd2ca42941fAuthor: latkin <latkin@microsoft.com>Date: Mon Oct 20 14:38:53 2014 -0700 Updating surface area testscommit 030e5eb32a7d6ec49c9bc28b420def58e0941213Merge:ef4388f 9120f09Author: latkin <latkin@microsoft.com>Date: Mon Oct 20 14:34:06 2014 -0700 Merge branch 'string_filter' ofhttps://git01.codeplex.com/forks/rojepp/vfs into PR2commit 9120f0920bad7b839df30e25bcf1a10244d53758Author: Robert Jeppesen <robert.jeppesen@durius.se>Date: Thu Jun 26 11:15:13 2014 +0200 Fix for portable buildcommit 96bb51932cff49568fd8f06202d40fb09387ec7bAuthor: Robert Jeppesen <robert.jeppesen@durius.se>Date: Thu Jun 26 09:32:34 2014 +0200 Implement String.filter
1 parenta0ccf49 commit6221ab5

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/StringModule.fs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ type StringModule() =
8585
lete2= String.mapi(fun i c-> c)null
8686
Assert.AreEqual("", e2)
8787

88+
[<Test>]
89+
memberthis.Filter()=
90+
lete1= String.filter(fun c->true)"foo"
91+
Assert.AreEqual("foo", e1)
92+
93+
lete2= String.filter(fun c->true)null
94+
Assert.AreEqual("", e2)
95+
96+
lete3= String.filter(fun c-> c<>'o')"foo bar"
97+
Assert.AreEqual("f bar", e3)
98+
99+
lete4= String.filter(fun c-> c<>'o')""
100+
Assert.AreEqual("", e4)
101+
88102
[<Test>]
89103
memberthis.Collect()=
90104
lete1= String.collect(fun c->"a"+string c)"foo"

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,7 @@ Microsoft.FSharp.Core.StringModule: Int32 GetHashCode()
27702770
Microsoft.FSharp.Core.StringModule: Int32 Length(System.String)
27712771
Microsoft.FSharp.Core.StringModule: System.String Collect(Microsoft.FSharp.Core.FSharpFunc`2[System.Char,System.String], System.String)
27722772
Microsoft.FSharp.Core.StringModule: System.String Concat(System.String, System.Collections.Generic.IEnumerable`1[System.String])
2773+
Microsoft.FSharp.Core.StringModule: System.String Filter(Microsoft.FSharp.Core.FSharpFunc`2[System.Char,System.Boolean], System.String)
27732774
Microsoft.FSharp.Core.StringModule: System.String Initialize(Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.String])
27742775
Microsoft.FSharp.Core.StringModule: System.String Map(Microsoft.FSharp.Core.FSharpFunc`2[System.Char,System.Char], System.String)
27752776
Microsoft.FSharp.Core.StringModule: System.String MapIndexed(Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Char,System.Char]], System.String)

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,6 +2750,7 @@ Microsoft.FSharp.Core.StringModule: Int32 GetHashCode()
27502750
Microsoft.FSharp.Core.StringModule: Int32 Length(System.String)
27512751
Microsoft.FSharp.Core.StringModule: System.String Collect(Microsoft.FSharp.Core.FSharpFunc`2[System.Char,System.String], System.String)
27522752
Microsoft.FSharp.Core.StringModule: System.String Concat(System.String, System.Collections.Generic.IEnumerable`1[System.String])
2753+
Microsoft.FSharp.Core.StringModule: System.String Filter(Microsoft.FSharp.Core.FSharpFunc`2[System.Char,System.Boolean], System.String)
27532754
Microsoft.FSharp.Core.StringModule: System.String Initialize(Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.String])
27542755
Microsoft.FSharp.Core.StringModule: System.String Map(Microsoft.FSharp.Core.FSharpFunc`2[System.Char,System.Char], System.String)
27552756
Microsoft.FSharp.Core.StringModule: System.String MapIndexed(Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Core.FSharpFunc`2[System.Char,System.Char]], System.String)

‎src/fsharp/FSharp.Core/string.fs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ namespace Microsoft.FSharp.Core
4646
str|> iteri(fun i c-> res.Append(f i c)|> ignore);
4747
res.ToString()
4848

49+
[<CompiledName("Filter")>]
50+
letfilter(f:char->bool)(str:string)=
51+
letstr= emptyIfNull str
52+
letres=new System.Text.StringBuilder(str.Length)
53+
str|> iter(fun c->if f cthen res.Append(c)|> ignore)
54+
res.ToString()
55+
4956
[<CompiledName("Collect")>]
5057
letcollect(f:char->string)(str:string)=
5158
letstr= emptyIfNull str

‎src/fsharp/FSharp.Core/string.fsi‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ namespace Microsoft.FSharp.Core
6464
[<CompiledName("Collect")>]
6565
valcollect:mapping:(char-> string)->str:string->string
6666

67+
/// <summary>Builds a new string containing only the characters of the input string
68+
/// for which the given predicate returns "true".</summary>
69+
///
70+
/// <remarks>Returns an empty string if the input string is null</remarks>
71+
///
72+
/// <param name="predicate">A function to test whether each character in the input sequence should be included in the output string.</param>
73+
/// <param name="str">The input string.</param>
74+
/// <returns>The resulting string.</returns>
75+
[<CompiledName("Filter")>]
76+
valfilter:predicate:(char-> bool)->str:string->string
77+
6778
/// <summary>Builds a new string whose characters are the results of applying the function <c>mapping</c>
6879
/// to each index from <c>0</c> to <c>count-1</c> and concatenating the resulting
6980
/// strings.</summary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp