function namedCurry(source_fn, arg_order){ | |
function receiver( received_values, n_received, defaults ){ | |
received_values = (received_values || []).slice() | |
n_received = n_received || 0 | |
Object.keys(defaults).forEach(function( input_arg ){ | |
var value = defaults[ input_arg ] | |
var required_index = arg_order.indexOf( input_arg ) | |
var is_known_argument = required_index > -1 | |
var existing_value = received_values[required_index] | |
if( is_known_argument ){ | |
if( typeof existing_value == "undefined" ){ | |
n_received++ | |
} | |
received_values[required_index] = value; | |
} | |
}) | |
if( n_received >= arg_order.length ){ | |
return source_fn.apply(null, received_values ) | |
} else { | |
return receiver.bind( null, received_values, n_received ) | |
} | |
} | |
return receiver.bind(null, null, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment