-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patheq.js
More file actions
91 lines (88 loc) · 2.67 KB
/
Copy patheq.js
File metadata and controls
91 lines (88 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const ComparisonOperator = require('./_internal/ComparisonOperator')
const equals = require('./_internal/equals')
/**
* @name eq
*
* @synopsis
* ```coffeescript [specscript]
* type Resolver = (...arguments)=>Promise|any
*
* eq(leftValue Promise|any, rightValue Promise|any) -> booleanResult Promise|boolean
* eq(...arguments, leftResolver Resolver, rightValue Promise|any) -> booleanResult Promise|boolean
* eq(...arguments, leftValue Promise|any, rightResolver Resolver) -> booleanResult Promise|boolean
* eq(...arguments, leftResolver Resolver, rightResolver Resolver) -> booleanResult Promise|boolean
*
* eq(leftResolver Resolver, rightValue Promise|any)(...arguments) -> booleanResult Promise|boolean
* eq(leftValue Promise|any, rightResolver Resolver)(...arguments) -> booleanResult Promise|boolean
* eq(leftResolver Resolver, rightResolver Resolver)(...arguments) -> booleanResult Promise|boolean
* ```
*
* @description
* Comparison operator. Tests for equality (`==`) between two values.
*
* ```javascript [playground]
* const areNamesEqual = eq('Ted', 'John')
*
* console.log(areNamesEqual)
* ```
*
* If either of the two values are resolver functions, `eq` returns a function that resolves the values to compare.
*
* ```javascript [playground]
* const personIsJohn = eq(get('name'), 'John')
* const personLikesBananas = eq(get('likes'), 'bananas')
*
* const person = { name: 'John', likes: 'bananas' }
*
* if (personIsJohn(person) && personLikesBananas(person)) {
* console.log('John likes bananas.')
* }
* ```
*
* If either of the two resolver functions is asynchronous, `eq` returns an asynchronous function.
*
* ```javascript [playground]
* const userbase = new Map()
*
* userbase.set('example-id', { name: 'John', likes: 'bananas' })
*
* async function getUserNameById(id) {
* const user = userbase.get(id)
* if (user) {
* return user.name
* }
* return undefined
* }
*
* const booleanResult = await eq('example-id', getUserNameById, 'John')
*
* console.log(booleanResult)
* ```
*
* `eq` supports a lazy interface for composability.
*
* ```javascript [playground]
* pipe({ name: 'John' }, [
* eq('John', get('name')),
* console.log,
* ])
* ```
*
* Any promises in `arguments` are resolved for their values before further execution for the eager interface only.
*
* ```javascript [playground]
* eq(Promise.resolve({ a: 1, b: 1 }), get('a'), get('b')).then(console.log)
* ```
*
* See also:
* * [and](/docs/and)
* * [gt](/docs/gt)
* * [lt](/docs/lt)
* * [gte](/docs/gte)
* * [lte](/docs/lte)
* * [thunkify](/docs/thunkify)
*
* @execution concurrent
*/
const eq = ComparisonOperator(equals)
module.exports = eq