@@ -106,15 +106,15 @@ public void CanGetFirst()
106106 [ Fact ]
107107 public void CanGetFirstMatch ( )
108108 {
109- static bool Predicate ( int x ) => ( x & 1 ) == 0 ;
109+ static bool IsEven ( int x ) => ( x & 1 ) == 0 ;
110110
111111 var empty = Array . Empty < int > ( ) ;
112112 var notEmpty = new [ ] { 3 , 5 , 6 , 7 , 8 , 9 } ;
113113 var noMatches = new [ ] { 1 , 3 , 5 , 7 } ;
114114
115- Assert . Equal ( None < int > ( ) , empty . FirstOrNone ( Predicate ) ) ;
116- Assert . Equal ( Some ( 6 ) , notEmpty . FirstOrNone ( Predicate ) ) ;
117- Assert . Equal ( None < int > ( ) , noMatches . FirstOrNone ( Predicate ) ) ;
115+ Assert . Equal ( None < int > ( ) , empty . FirstOrNone ( IsEven ) ) ;
116+ Assert . Equal ( Some ( 6 ) , notEmpty . FirstOrNone ( IsEven ) ) ;
117+ Assert . Equal ( None < int > ( ) , noMatches . FirstOrNone ( IsEven ) ) ;
118118 }
119119
120120 [ Fact ]
@@ -140,7 +140,7 @@ public void CanGetLast()
140140 [ Fact ]
141141 public void CanGetLastMatch ( )
142142 {
143- static bool Predicate ( int x ) => ( x & 1 ) == 0 ;
143+ static bool IsEven ( int x ) => ( x & 1 ) == 0 ;
144144
145145 IList < int > empty = Array . Empty < int > ( ) ;
146146 IReadOnlyList < int > emptyReadOnly = new ReadOnlyList < int > ( empty ) ;
@@ -154,17 +154,17 @@ public void CanGetLastMatch()
154154 IReadOnlyList < int > noMatchesReadOnly = new ReadOnlyList < int > ( noMatches ) ;
155155 IEnumerable < int > noMatchesEnumerable = Enumerate ( noMatches ) ;
156156
157- Assert . Equal ( None < int > ( ) , empty . LastOrNone ( Predicate ) ) ;
158- Assert . Equal ( None < int > ( ) , emptyReadOnly . LastOrNone ( Predicate ) ) ;
159- Assert . Equal ( None < int > ( ) , emptyEnumerable . LastOrNone ( Predicate ) ) ;
157+ Assert . Equal ( None < int > ( ) , empty . LastOrNone ( IsEven ) ) ;
158+ Assert . Equal ( None < int > ( ) , emptyReadOnly . LastOrNone ( IsEven ) ) ;
159+ Assert . Equal ( None < int > ( ) , emptyEnumerable . LastOrNone ( IsEven ) ) ;
160160
161- Assert . Equal ( Some ( 8 ) , notEmpty . LastOrNone ( Predicate ) ) ;
162- Assert . Equal ( Some ( 8 ) , notEmptyReadOnly . LastOrNone ( Predicate ) ) ;
163- Assert . Equal ( Some ( 8 ) , notEmptyEnumerable . LastOrNone ( Predicate ) ) ;
161+ Assert . Equal ( Some ( 8 ) , notEmpty . LastOrNone ( IsEven ) ) ;
162+ Assert . Equal ( Some ( 8 ) , notEmptyReadOnly . LastOrNone ( IsEven ) ) ;
163+ Assert . Equal ( Some ( 8 ) , notEmptyEnumerable . LastOrNone ( IsEven ) ) ;
164164
165- Assert . Equal ( None < int > ( ) , noMatches . LastOrNone ( Predicate ) ) ;
166- Assert . Equal ( None < int > ( ) , noMatchesReadOnly . LastOrNone ( Predicate ) ) ;
167- Assert . Equal ( None < int > ( ) , noMatchesEnumerable . LastOrNone ( Predicate ) ) ;
165+ Assert . Equal ( None < int > ( ) , noMatches . LastOrNone ( IsEven ) ) ;
166+ Assert . Equal ( None < int > ( ) , noMatchesReadOnly . LastOrNone ( IsEven ) ) ;
167+ Assert . Equal ( None < int > ( ) , noMatchesEnumerable . LastOrNone ( IsEven ) ) ;
168168 }
169169
170170 [ Fact ]
@@ -198,7 +198,7 @@ public void CanGetSingle()
198198 [ Fact ]
199199 public void CanGetSingleMatch ( )
200200 {
201- static bool Predicate ( int x ) => ( x & 1 ) == 0 ;
201+ static bool IsEven ( int x ) => ( x & 1 ) == 0 ;
202202
203203 var empty = Array . Empty < int > ( ) ;
204204 var singleWithMatch = new [ ] { 4 } ;
@@ -207,12 +207,12 @@ public void CanGetSingleMatch()
207207 var manyNoMatch = new [ ] { 3 , 5 } ;
208208 var manyWithManyMatches = new [ ] { 2 , 3 , 4 , 5 , 6 } ;
209209
210- Assert . Equal ( None < int > ( ) , empty . SingleOrNone ( Predicate ) ) ;
211- Assert . Equal ( Some ( 4 ) , singleWithMatch . SingleOrNone ( Predicate ) ) ;
212- Assert . Equal ( None < int > ( ) , singleNoMatch . SingleOrNone ( Predicate ) ) ;
213- Assert . Equal ( Some ( 4 ) , manyWithMatch . SingleOrNone ( Predicate ) ) ;
214- Assert . Equal ( None < int > ( ) , manyNoMatch . SingleOrNone ( Predicate ) ) ;
215- Assert . Equal ( None < int > ( ) , manyWithManyMatches . SingleOrNone ( Predicate ) ) ;
210+ Assert . Equal ( None < int > ( ) , empty . SingleOrNone ( IsEven ) ) ;
211+ Assert . Equal ( Some ( 4 ) , singleWithMatch . SingleOrNone ( IsEven ) ) ;
212+ Assert . Equal ( None < int > ( ) , singleNoMatch . SingleOrNone ( IsEven ) ) ;
213+ Assert . Equal ( Some ( 4 ) , manyWithMatch . SingleOrNone ( IsEven ) ) ;
214+ Assert . Equal ( None < int > ( ) , manyNoMatch . SingleOrNone ( IsEven ) ) ;
215+ Assert . Equal ( None < int > ( ) , manyWithManyMatches . SingleOrNone ( IsEven ) ) ;
216216 }
217217
218218 [ Fact ]
@@ -245,6 +245,20 @@ public void CanGetElementAt()
245245 Assert . Equal ( Some ( 5 ) , notEmptyEnumerable . ElementAtOrNone ( 5 ) ) ;
246246 }
247247
248+ [ Fact ]
249+ public void CanSelectWhere ( )
250+ {
251+ var strings = new [ ] { "1" , "two" , "NaN" , "four" , "5" , "six" , "7" , "eight" , "9" , "10" } ;
252+
253+ #if NET7_0_OR_GREATER
254+ var ints = strings . SelectWhere ( Option . Parse < int > ) ;
255+ #else
256+ var ints = strings . SelectWhere ( Option . Bind < string , int > ( int . TryParse ) ) ;
257+ #endif
258+
259+ Assert . Equal ( new [ ] { 1 , 5 , 7 , 9 , 10 } , ints ) ;
260+ }
261+
248262 [ Fact ]
249263 public void CanPeekStack ( )
250264 {
0 commit comments