Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Commit dab9059

Browse files
author
Bo Lingen
committed
docs(readme): binary expression docs
1 parent 25eda0f commit dab9059

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

readme.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [spread placeholders](#spread-placeholders): `Math.max(..._)`
1010
- [lambda parameters](#lambda-parameters): `people.map(_.name)`
1111
- [object placeholders](#object-placeholders): `_.hasOwnProperty('dapper')`
12+
- [binary expressions](#binary-expressions): `_ === 'awesome'`, `_.getPower().level > 9000`
1213
- [usage](#usage)
1314
- [babelrc](#babelrc)
1415
- [babel-cli](#babel-cli)
@@ -166,6 +167,43 @@ hasOwn(object, 'flammable')
166167
// -> true
167168
```
168169

170+
### binary expressions
171+
172+
You can use placeholders within logical comparisons ( `===` ) or
173+
addition, subtraction, string concatenation, etc. So this:
174+
175+
```js
176+
array.map(_ === true)
177+
```
178+
179+
... transforms into this:
180+
181+
```js
182+
array.map(_b => {
183+
return _b === true
184+
})
185+
```
186+
187+
And for a classic example, let's say you have an Array of numbers
188+
and want the total sum of them all:
189+
190+
```js
191+
const array = [1, 2, 3, 4, 5]
192+
array.reduce(_ + _)
193+
// -> 15
194+
```
195+
196+
You can combine this with object placeholders and lambda parameters:
197+
198+
```js
199+
const heroes = [
200+
{ getPower () { return { level: 9001 } } }
201+
{ getPower () { return { level: 4500 } } }
202+
]
203+
204+
heroes.filter(_.getPower().level > 9000)
205+
```
206+
169207
### curried-style functions
170208

171209
A handy usage for this plugin is emulating "curried" style functions,

0 commit comments

Comments
 (0)