Created
January 4, 2013 01:27
-
-
Save Gozala/4449153 to your computer and use it in GitHub Desktop.
Restructures items using given `f`.
This file contains 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
function restructure(input, f, start) { | |
return reducible(function(next, initial) { | |
var state = start | |
return reduce(input, function(item, result) { | |
var change = [].concat(f(item, state)) | |
state = change[0] | |
var value = change[1] | |
return value ? next(value, result) : | |
result | |
}, initial) | |
}) | |
} |
Author
Gozala
commented
Jan 4, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment