Last active
          July 23, 2021 23:49 
        
      - 
      
 - 
        
Save jhunterkohler/3e9b30253973e88f61be469b159d972e to your computer and use it in GitHub Desktop.  
    Chain input/outputs of functions together
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | export function flow(...fn) { | |
| return function (...args) { | |
| let ret = fn[0].apply(this, args); | |
| let index = 1; | |
| let { length } = fn; | |
| while (index < length) { | |
| ret = fn.call(this, ret); | |
| index++; | |
| } | |
| return ret; | |
| }; | |
| } | |
| export async function asyncFlow(...fn) { | |
| return function (...args) { | |
| let ret = await fn[0].apply(this, args); | |
| let index = 1; | |
| let { length } = fn; | |
| while (index < length) { | |
| ret = await fn.call(this, ret); | |
| index++; | |
| } | |
| return ret; | |
| }; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment