 
 _emptyFn = ()->
 
-cutFlowsByArity = (flowFns, arity)->
-  debug 'cutFlowsByArity  ', arity     
-  for fn, inx in flowFns
-    debug 'fn.length', fn.length
-    if not _isArray(fn) and fn.length is arity
-      return flowFns[inx..] 
-  return []
+# cutFlowsByArity = (flowFns, arity)->
+#   debug 'cutFlowsByArity  ', arity     
+#   for fn, inx in flowFns
+#     debug 'fn.length', fn.length
+#     if not _isArray(fn) and fn.length is arity
+#       return flowFns[inx..] 
+#   return []
 
 unifyErrors = (errors)->
   errs = errors.filter (err)-> err 


runFlow = (flowFns, err, args, outCallback)->
  debug 'runFlow start', err, args
  errorHandlerArity = args.length + 2 # include err, callback
  if err
    flowFns = cutFlowsByArity(flowFns, errorHandlerArity)    
  
  return outCallback err, args... if flowFns.length is 0 
  
  [fn, fns...] = flowFns  

  if _isArray fn 
    fnArr = fn.map (flow)->  

  return fns
  

_fn.fork = (forkingFns)->
  return (args..., outCallback)->      
    if typeof outCallback isnt 'function'
      args.push outCallback
      outCallback = ()-> 
    runFork forkingFns, args, outCallback
_fn.fork.do = (args..., forkingFns, outCallback)->
  f = _fn.fork forkingFns
  f args..., outCallback 


_fn.flow = (flowFns)->
  _validating flowFns
  return (args..., outCallback)->  

    first = args[0]
    err = null
    # debug 'first', first
    if first is null or first is undefined or _isError first
      err = args.shift()
      debug 'set err = ', err
  
    if outCallback and typeof outCallback isnt 'function'
      args.push outCallback
      outCallback = undefined
    unless outCallback
      outCallback = _emptyFn

    # debug '_fn.flow arity = ', args.length
    debug '_fn.flow ', 'err =',err, 'args=', args, 'outCallback=', outCallback , '<--', arguments
    runFlow flowFns, err, args, outCallback

_fn.flow.do = (args..., flowFns)->
  fn = _fn.flow flowFns
  fn args...

#############################################
# 유틸리티 고계도 함수

_fn.retry = (tryLimit, fn)->
  return (args..., outCallback)->
    debug 'fnRetry'
