5
5
6
6
import { PredicateWithIndex } from '@tsdotnet/common-interfaces' ;
7
7
import LinqBase from "./LinqBase" ;
8
- import where from './filters/where' ;
9
8
import all from './resolutions/all' ;
10
9
import any from './resolutions/any' ;
11
10
import count from './resolutions/count' ;
@@ -38,19 +37,17 @@ export default abstract class LinqExtendedBase<T, TLinq extends LinqExtendedBase
38
37
* Returns the number of entries in a sequence.
39
38
* If a predicate is provided, filters the count based upon the predicate.
40
39
* Otherwise counts all the entries in the sequence.
41
- * @param {PredicateWithIndex<T> } predicate
40
+ * @param {PredicateWithIndex<T> } [ predicate]
42
41
* @return {boolean }
43
42
*/
44
43
count ( predicate ?: PredicateWithIndex < T > ) : number {
45
- return predicate
46
- ? count ( where ( predicate ) ( this . source ) )
47
- : count ( this . source ) ;
44
+ return count ( predicate ? this . where ( predicate ) : this . source ) ;
48
45
}
49
46
50
47
/**
51
48
* Returns true if the predicate ever returns true; otherwise false.
52
49
* If no predicate is provided, returns true if the sequence has any entries.
53
- * @param {PredicateWithIndex<T> } predicate
50
+ * @param {PredicateWithIndex<T> } [ predicate]
54
51
* @return {boolean }
55
52
*/
56
53
any ( predicate ?: PredicateWithIndex < T > ) : boolean {
@@ -59,7 +56,7 @@ export default abstract class LinqExtendedBase<T, TLinq extends LinqExtendedBase
59
56
60
57
/**
61
58
* Returns false if the predicate ever returns false; otherwise true.
62
- * @param {PredicateWithIndex<T> } predicate
59
+ * @param {PredicateWithIndex<T> } [ predicate]
63
60
* @return {boolean }
64
61
*/
65
62
all ( predicate : PredicateWithIndex < T > ) : boolean {
@@ -68,62 +65,83 @@ export default abstract class LinqExtendedBase<T, TLinq extends LinqExtendedBase
68
65
69
66
/**
70
67
* Returns the expected single element; otherwise throws an InvalidOperationException.
68
+ * @param {PredicateWithIndex<T> } [predicate]
69
+ * @return {T }
71
70
*/
72
71
single ( predicate ?: PredicateWithIndex < T > ) : T {
73
72
return single ( predicate ? this . where ( predicate ) : this . source ) ;
74
73
}
75
74
76
75
/**
77
76
* Returns the expected single element; otherwise the provided default value.
77
+ * @param {T } defaultValue
78
+ * @param {PredicateWithIndex<T> } [predicate]
79
+ * @return {T }
78
80
*/
79
81
singleOrDefault ( defaultValue : T , predicate ?: PredicateWithIndex < T > ) : T {
80
82
return singleOrDefault ( defaultValue ) ( predicate ? this . where ( predicate ) : this . source ) ;
81
83
}
82
84
83
85
/**
84
86
* Returns the expected single element; otherwise undefined.
87
+ * @param {PredicateWithIndex<T> } [predicate]
88
+ * @return {T | undefined }
85
89
*/
86
90
singleOrUndefined ( predicate ?: PredicateWithIndex < T > ) : T | undefined {
87
91
return singleOrDefault < T | undefined > ( undefined ) ( predicate ? this . where ( predicate ) : this . source ) ;
88
92
}
89
93
90
94
/**
91
95
* Returns the first element of the sequence.
96
+ * @param {PredicateWithIndex<T> } [predicate]
97
+ * @return {T }
92
98
*/
93
99
first ( predicate ?: PredicateWithIndex < T > ) : T {
94
100
return first ( predicate ? this . where ( predicate ) : this . source ) ;
95
101
}
96
102
97
103
/**
98
104
* Returns the first element of the sequence or the default value if no element is found.
105
+ * @param {T } defaultValue
106
+ * @param {PredicateWithIndex<T> } [predicate]
107
+ * @return {T }
99
108
*/
100
109
firstOrDefault ( defaultValue : T , predicate ?: PredicateWithIndex < T > ) : T {
101
110
return firstOrDefault ( defaultValue ) ( predicate ? this . where ( predicate ) : this . source ) ;
102
111
}
103
112
104
113
/**
105
114
* Returns the first element of the sequence; otherwise undefined.
115
+ * @param {PredicateWithIndex<T> } [predicate]
116
+ * @return {T | undefined }
106
117
*/
107
118
firstOrUndefined ( predicate ?: PredicateWithIndex < T > ) : T | undefined {
108
119
return firstOrDefault < T | undefined > ( undefined ) ( predicate ? this . where ( predicate ) : this . source ) ;
109
120
}
110
121
111
122
/**
112
123
* Returns the last element of the sequence.
124
+ * @param {PredicateWithIndex<T> } [predicate]
125
+ * @return {T }
113
126
*/
114
127
last ( predicate ?: PredicateWithIndex < T > ) : T {
115
128
return last ( predicate ? this . where ( predicate ) : this . source ) ;
116
129
}
117
130
118
131
/**
119
132
* Returns the last element of the sequence or the default value if no element is found.
133
+ * @param {T } defaultValue
134
+ * @param {PredicateWithIndex<T> } [predicate]
135
+ * @return {T }
120
136
*/
121
137
lastOrDefault ( defaultValue : T , predicate ?: PredicateWithIndex < T > ) : T {
122
138
return lastOrDefault ( defaultValue ) ( predicate ? this . where ( predicate ) : this . source ) ;
123
139
}
124
140
125
141
/**
126
142
* Returns the last element of the sequence; otherwise undefined.
143
+ * @param {PredicateWithIndex<T> } [predicate]
144
+ * @return {T | undefined }
127
145
*/
128
146
lastOrUndefined ( predicate ?: PredicateWithIndex < T > ) : T | undefined {
129
147
return lastOrDefault < T | undefined > ( undefined ) ( predicate ? this . where ( predicate ) : this . source ) ;
0 commit comments