Skip to content

Commit

Permalink
✨ Feat: introduce getValue
Browse files Browse the repository at this point in the history
  • Loading branch information
JPeer264 committed Apr 4, 2017
1 parent 30864be commit 1104667
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $ yarn add bearray
- [filter](#filter)
- [map](#map)
- [reduce](#reduce)
- [getValue](#getValue)

### filter
> Ƹ̵̡Ӝ̵̨̄Ʒ
Expand All @@ -33,7 +34,7 @@ const ᕕ·ᐛ·ᕗ = ʕ·ᴥ·ʔ([1, 2, 3, 4]).Ƹ̵̡Ӝ̵̨̄Ʒ((value, index)
return value % 2 === 0;
});

ᕕ·ᐛ·ᕗ.output // [2, 4]
ᕕ·ᐛ·ᕗ.ʕᵔᴥᵔʔ() // [2, 4]
```

### map
Expand All @@ -48,7 +49,7 @@ const ᕕ·ᐛ·ᕗ = ʕ·ᴥ·ʔ([1, 2, 3, 4]).ʕʘ̅͜ʘ̅ʔ((value, index) =>
return value + value;
});

ᕕ·ᐛ·ᕗ.output // [2, 4, 6, 8]
ᕕ·ᐛ·ᕗ.ʕᵔᴥᵔʔ() // [2, 4, 6, 8]
```

### reduce
Expand All @@ -64,5 +65,18 @@ const ᕕ·ᐛ·ᕗ = ʕ·ᴥ·ʔ([1, 2, 3, 4]).ಠ_ಠ((sum, current) => {
});


ᕕ·ᐛ·ᕗ.output // [10]
ᕕ·ᐛ·ᕗ.ʕᵔᴥᵔʔ() // [10]
```

### getValue
> ʕᵔᴥᵔʔ
Get the value at the end of some chained operations (see other functions as well).

```js
import { ʕ·ᴥ·ʔ } from 'bearray';

const ᕕ·ᐛ·ᕗ = ʕ·ᴥ·ʔ([1, 2, 3, 4]);

ᕕ·ᐛ·ᕗ.ʕᵔᴥᵔʔ() // [1, 2, 3, 4]
```
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ const ʕ·ᴥ·ʔ = function (input) {
return this;
};

const ʕᵔᴥᵔʔ = function () {
return this.output;
};

return {
ʕʘ̅͜ʘ̅ʔ,
Ƹ̵̡Ӝ̵̨̄Ʒ,
ಠ_ಠ,
ʕᵔᴥᵔʔ,
};
};

Expand Down
8 changes: 4 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ test('fails on non array in reduce', (t) => {
test('reduce an array', (t) => {
const reduce = ʕ·ᴥ·ʔ(arr).ಠ_ಠ((prev, curr) => prev + curr);

t.deepEqual(reduce.output, [10]);
t.deepEqual(reduce.ʕᵔᴥᵔʔ(), [10]);
});

test('filter all odds of an array', (t) => {
const filter = ʕ·ᴥ·ʔ(arr).Ƹ̵̡Ӝ̵̨̄Ʒ(value => value % 2 === 0);

t.deepEqual(filter.output, [2, 4]);
t.deepEqual(filter.ʕᵔᴥᵔʔ(), [2, 4]);
});

test('multiply all elements by 2', (t) => {
const map = ʕ·ᴥ·ʔ(arr).ʕʘ̅͜ʘ̅ʔ(value => value * value);

t.deepEqual(map.output, [1, 4, 9, 16]);
t.deepEqual(map.ʕᵔᴥᵔʔ(), [1, 4, 9, 16]);
});

test('chain some methods', (t) => {
const map = ʕ·ᴥ·ʔ(arr).ʕʘ̅͜ʘ̅ʔ(value => value + 1)
.Ƹ̵̡Ӝ̵̨̄Ʒ(value => value % 2 === 0)
.ಠ_ಠ((prev, curr) => prev + curr);

t.deepEqual(map.output, [6]);
t.deepEqual(map.ʕᵔᴥᵔʔ(), [6]);
});

test('🥚', (t) => {
Expand Down

0 comments on commit 1104667

Please sign in to comment.