Skip to content

Commit

Permalink
Optimizing space
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Jul 21, 2016
1 parent 372ba4c commit 2f037d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
33 changes: 5 additions & 28 deletions lib/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,10 @@ export function* DistinctFast<T>(target: Iterable<T>) {
}


export function* OfType<T>(target: Iterable<T>, obj: any) {
if (Number === obj) {
export function* OfType<T>(target: Iterable<T>, obj: any, typeName: string) {
if (typeName){
for (let value of target) {
if (Constant.CONST_NUMBER == typeof(value)) {
yield value;
} else if (value instanceof obj) {
yield value;
}
}
} else if (Boolean === obj) {
for (let value of target) {
if (Constant.CONST_BOOLEAN == typeof(value)) {
yield value;
} else if (value instanceof obj) {
yield value;
}
}
} else if (String === obj) {
for (let value of target) {
if (Constant.CONST_STRING == typeof(value)) {
yield value;
} else if (value instanceof obj) {
yield value;
}
}
} else if (Symbol === obj) {
for (let value of target) {
if (Constant.CONST_SYMBOL == typeof(value)) {
if (typeName == typeof(value)) {
yield value;
} else if (value instanceof obj) {
yield value;
Expand All @@ -111,7 +87,8 @@ export function* OfType<T>(target: Iterable<T>, obj: any) {
}


export function* Where<T>(target: Iterable<T>, predicate: (x: T, i: number) => Boolean) {
export function* Where<T>(target: Iterable<T>,
predicate: (x: T, i: number) => Boolean) {
let index = 0;
for (let value of target) {
if (!predicate(value, index++)) continue;
Expand Down
24 changes: 23 additions & 1 deletion lib/linq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,29 @@ class EnumerableImpl<T> implements Enumerable<T>, Iterable<T>, IEnumerable<T> {


public OfType(obj: any): Enumerable<T> {
this._target = Generator.OfType(this._target, obj);
let typeName: string;
switch (obj) {
case Number:
typeName = Constant.CONST_NUMBER;
break;

case Boolean:
typeName = Constant.CONST_BOOLEAN;
break;

case String:
typeName = Constant.CONST_STRING;
break;

case Symbol:
typeName = Constant.CONST_SYMBOL;
break;

default:
typeName = undefined;
}

this._target = Generator.OfType(this._target, obj, typeName);
return this;
}

Expand Down

0 comments on commit 2f037d6

Please sign in to comment.