Skip to content

Commit c3b8380

Browse files
committed
fixing small bugs
1 parent bd98b0d commit c3b8380

File tree

6 files changed

+31
-26
lines changed

6 files changed

+31
-26
lines changed

crossproduct.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import curryN from "./utils/curry_n.ts"
22
import { Curry2 } from "./utils/types.ts"
33

4-
5-
/** Creates a new list out of the two supplied by creating each possible pair
6-
* from the list passed as arguments.
7-
* @function
8-
*
9-
* Fae.xprod([1, 2, 3], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'], [3, 'a'], [3, 'b']]
10-
*/
11-
124
function crossproduct(a: Array<any>, b: Array<any>) {
135
let result = []
146
for(let idx = 0; idx < a.length; idx++)
157
for(let j = 0; j < b.length; j++)
168
result[result.length] = [a[idx], b[j]]
179
return result
1810
}
11+
12+
/** Creates a new list out of the two supplied by creating each possible pair
13+
* from the list passed as arguments.
14+
*
15+
* Fae.crossproduct([1, 2, 3], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'], [3, 'a'], [3, 'b']]
16+
*/
1917
export default curryN(2, crossproduct) as Curry2<Array<any>>

reject.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ import { Func, Curry2, Obj, Predicate1 } from "./utils/types.ts"
33
import complement from './complement.ts';
44
import filter from './filter.ts';
55

6+
function reject<T>(pred: Predicate1, filterable: Array<T> | Obj) {
7+
return filter(complement(pred), filterable)
8+
}
9+
610
/** works as the complement of filter
7-
* @function
811
*
912
* const isOdd = n => (n & 1) === 1;
1013
* const f = Fae.reject(isOdd, [1, 2, 3, 4])
1114
* f() // [2, 4]
1215
*/
13-
14-
function reject<T>(pred: Predicate1, filterable: Array<T> | Obj) {
15-
return filter(complement(pred), filterable)
16-
}
17-
18-
export default curryN(2, reject) as Curry2<Func, Array<any> | Obj, Array<any> | Obj>
16+
export default curryN(2, reject) as Curry2<Predicate1, Array<any> | Obj, Array<any> | Obj>

specs/whereEq.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it } from "./_describe.ts"
2-
import { whereEq, curry } from '../mod.ts'
2+
import { whereEq } from '../mod.ts'
33
import { eq } from "./utils/utils.ts"
44

55

utils/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export type ObjArr<T = any> = {
4646
}
4747

4848
export type ObjRec<T = number> = {
49-
[key: string]: ObjRec | ObjArr | string | number | T
49+
[key: string]: ObjRec | ObjArr | string | number | null | undefined | T
5050
}
5151

5252
export type Comparator<T> = (a: T, b: T) => 1 | -1 | 0

whereEq.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@ import curryN from "./utils/curry_n.ts"
22
import { Curry2, ObjRec, Obj } from "./utils/types.ts"
33
import where from "./where.ts"
44
import map from "./map.ts"
5-
import curry from './curry.ts'
5+
import equals from './equals.ts'
66

77
function whereEq(spec: ObjRec, testObj: ObjRec) {
8-
const equals = curry(2, (x: number, y: number) => x === y)
98
return where(map(equals, spec), testObj)
109
}
1110

12-
export default curryN(2, whereEq) as Curry2<Obj, ObjRec, boolean>
11+
/**
12+
* Takes a spec object and a test object, returns true if the test satisfies
13+
* the spec, false otherwise.
14+
* `whereEq` is a specialization of [`where`].
15+
*
16+
* const pred = Fae.whereEq({a: 1, b: 2})
17+
*
18+
* pred({a: 1}) //=> false
19+
* pred({a: 1, b: 2}) //=> true
20+
* pred({a: 1, b: 2, c: 3}) //=> true
21+
* pred({a: 1, b: 1}) //=> false
22+
*/
23+
export default curryN(2, whereEq) as Curry2<ObjRec, ObjRec, boolean>

xor.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import curryN from "./utils/curry_n.ts"
22
import { Curry2, Obj } from "./utils/types.ts"
33

4+
function xor(a: any, b: any) {
5+
return Boolean(a ? !b : b)
6+
}
7+
48
/** Exclusive Or - Returns `true` if one of the arguments is truthy and the other is falsy.
59
* Otherwise, it returns `false`.
6-
* @function
710
*
811
* Fae.xor(true, true) //=> false
912
* Fae.xor(true, false) //=> true
1013
* Fae.xor(false, true) //=> true
1114
* Fae.xor(false, false) //=> false
1215
*/
13-
14-
function xor(a: any, b: any) {
15-
return Boolean(a ? !b : b)
16-
}
17-
1816
export default curryN(2, xor) as Curry2<any, any, boolean>

0 commit comments

Comments
 (0)