renamed .then(..) to .after(..) and added .before(..) -- not sure if we'll keep these, seem to be overcomplicating things...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-03-21 13:42:00 +03:00
parent e962f75ed2
commit 1c18b2eb1b
2 changed files with 52 additions and 3 deletions

View File

@ -20,19 +20,38 @@ object.Mixin('FunctionProtoMixin', 'soft', {
// instance methods will lose context:
// ;[1,3,2]
// .sort
// .then(function(res){
// .post(function(res){
// return res.pop() })
//
// a better way to do this:
// ;[1,3,2]
// .sort()
// .pop()
//
// and a better way to use this is:
// Array.prototype.greatest =
// Array.prototype
// .sort
// .then(function(res){
// .post(function(res){
// return res.pop() })
then: function(func){
//
// XXX this more complicated and less clear than:
// Array.prototype.greatest =
// function(){
// return this
// .sort()
// .pop() }
// ...are there cases when this is actually needed???
// XXX add doc...
before: function(func){
var that = this
return function(){
var res = func.call(this, ...arguments)
res = res === undefined ?
that
: res
return res.call(this, ...arguments) }},
after: function(func){
var that = this
return function(){
return func.call(this,

View File

@ -13,6 +13,9 @@ A library of JavaScript type extensions, types and type utilities.
- [`Object.matchPartial(..)`](#objectmatchpartial)
- [`<object>.run(..)`](#objectrun)
- [`Object.sort(..)`](#objectsort)
- [`Function`](#function)
- [`<function>.before(..)` (EXPERIMENTAL)](#functionbefore-experimental)
- [`<function>.after(..)` (EXPERIMENTAL)](#functionafter-experimental)
- [`Array`](#array)
- [`<array>.first(..)` / `<array>.last(..)`](#arrayfirst--arraylast)
- [`<array>.rol(..)`](#arrayrol)
@ -324,6 +327,33 @@ Object.keys(Object.sort(o, ['x', 'a', '100']))
```
## `Function`
```javascript
require('ig-types/Function')
```
### `<function>.before(..)` (EXPERIMENTAL)
```bnf
<function>.before(<func>)
-> <function>
<func>(...args)
-> <res>
```
### `<function>.after(..)` (EXPERIMENTAL)
```bnf
<function>.after(<func>)
-> <function>
<func>(<res>, ...args)
-> <res>
```
## `Array`