Skip to content

Commit b0869fd

Browse files
Revised doc comments.
1 parent 96b5c66 commit b0869fd

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/LinqExtendedBase.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { PredicateWithIndex } from '@tsdotnet/common-interfaces';
77
import LinqBase from "./LinqBase";
8-
import where from './filters/where';
98
import all from './resolutions/all';
109
import any from './resolutions/any';
1110
import count from './resolutions/count';
@@ -38,19 +37,17 @@ export default abstract class LinqExtendedBase<T, TLinq extends LinqExtendedBase
3837
* Returns the number of entries in a sequence.
3938
* If a predicate is provided, filters the count based upon the predicate.
4039
* Otherwise counts all the entries in the sequence.
41-
* @param {PredicateWithIndex<T>} predicate
40+
* @param {PredicateWithIndex<T>} [predicate]
4241
* @return {boolean}
4342
*/
4443
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);
4845
}
4946

5047
/**
5148
* Returns true if the predicate ever returns true; otherwise false.
5249
* If no predicate is provided, returns true if the sequence has any entries.
53-
* @param {PredicateWithIndex<T>} predicate
50+
* @param {PredicateWithIndex<T>} [predicate]
5451
* @return {boolean}
5552
*/
5653
any(predicate?: PredicateWithIndex<T>): boolean {
@@ -59,7 +56,7 @@ export default abstract class LinqExtendedBase<T, TLinq extends LinqExtendedBase
5956

6057
/**
6158
* Returns false if the predicate ever returns false; otherwise true.
62-
* @param {PredicateWithIndex<T>} predicate
59+
* @param {PredicateWithIndex<T>} [predicate]
6360
* @return {boolean}
6461
*/
6562
all(predicate: PredicateWithIndex<T>): boolean {
@@ -68,62 +65,83 @@ export default abstract class LinqExtendedBase<T, TLinq extends LinqExtendedBase
6865

6966
/**
7067
* Returns the expected single element; otherwise throws an InvalidOperationException.
68+
* @param {PredicateWithIndex<T>} [predicate]
69+
* @return {T}
7170
*/
7271
single(predicate?: PredicateWithIndex<T>): T {
7372
return single(predicate ? this.where(predicate) : this.source);
7473
}
7574

7675
/**
7776
* Returns the expected single element; otherwise the provided default value.
77+
* @param {T} defaultValue
78+
* @param {PredicateWithIndex<T>} [predicate]
79+
* @return {T}
7880
*/
7981
singleOrDefault(defaultValue: T, predicate?: PredicateWithIndex<T>): T {
8082
return singleOrDefault(defaultValue)(predicate ? this.where(predicate) : this.source);
8183
}
8284

8385
/**
8486
* Returns the expected single element; otherwise undefined.
87+
* @param {PredicateWithIndex<T>} [predicate]
88+
* @return {T | undefined}
8589
*/
8690
singleOrUndefined(predicate?: PredicateWithIndex<T>): T | undefined {
8791
return singleOrDefault<T | undefined>(undefined)(predicate ? this.where(predicate) : this.source);
8892
}
8993

9094
/**
9195
* Returns the first element of the sequence.
96+
* @param {PredicateWithIndex<T>} [predicate]
97+
* @return {T}
9298
*/
9399
first(predicate?: PredicateWithIndex<T>): T {
94100
return first(predicate ? this.where(predicate) : this.source);
95101
}
96102

97103
/**
98104
* 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}
99108
*/
100109
firstOrDefault(defaultValue: T, predicate?: PredicateWithIndex<T>): T {
101110
return firstOrDefault(defaultValue)(predicate ? this.where(predicate) : this.source);
102111
}
103112

104113
/**
105114
* Returns the first element of the sequence; otherwise undefined.
115+
* @param {PredicateWithIndex<T>} [predicate]
116+
* @return {T | undefined}
106117
*/
107118
firstOrUndefined(predicate?: PredicateWithIndex<T>): T | undefined {
108119
return firstOrDefault<T | undefined>(undefined)(predicate ? this.where(predicate) : this.source);
109120
}
110121

111122
/**
112123
* Returns the last element of the sequence.
124+
* @param {PredicateWithIndex<T>} [predicate]
125+
* @return {T}
113126
*/
114127
last(predicate?: PredicateWithIndex<T>): T {
115128
return last(predicate ? this.where(predicate) : this.source);
116129
}
117130

118131
/**
119132
* 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}
120136
*/
121137
lastOrDefault(defaultValue: T, predicate?: PredicateWithIndex<T>): T {
122138
return lastOrDefault(defaultValue)(predicate ? this.where(predicate) : this.source);
123139
}
124140

125141
/**
126142
* Returns the last element of the sequence; otherwise undefined.
143+
* @param {PredicateWithIndex<T>} [predicate]
144+
* @return {T | undefined}
127145
*/
128146
lastOrUndefined(predicate?: PredicateWithIndex<T>): T | undefined {
129147
return lastOrDefault<T | undefined>(undefined)(predicate ? this.where(predicate) : this.source);

0 commit comments

Comments
 (0)