Last active
June 21, 2018 15:47
-
-
Save christianwish/50316ec6d6f26e795bdb41c5924d02a6 to your computer and use it in GitHub Desktop.
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
# pythonw ./index.py | |
# clear terminal !!! Cool | |
# print("\033[H\033[J") | |
CRED = '\033[91m' | |
CEND = '\033[0m' | |
def logError(msg, info): | |
print CRED | |
print("[ERROR] " + msg + " :") | |
print(" got: " + str(info) + "\n") | |
print CEND | |
def compose(*args): | |
length = len(args) | |
def _composeInner(lastResult, index): | |
if ((length - 1) < index): | |
return lastResult | |
return _composeInner(args[index](lastResult), index + 1) | |
return (lambda x: _composeInner(x, 0)) | |
def filter(arr, fn): | |
resultArray = [] | |
for element in arr: | |
if (fn(element)): | |
resultArray.append( | |
fn(element) | |
) | |
return resultArray | |
def reduce(arr, fn, startInput): | |
def _reduceInner(arr, fn, acc, i): | |
if (i == len(arr)): | |
return acc | |
newAcc = fn(acc, arr[i]) | |
return _reduceInner(arr, fn, newAcc, (i + 1)) | |
return _reduceInner(arr, fn, startInput, 0) | |
def map(arr, fn): | |
resultArray = [] | |
for element in arr: | |
resultArray.append( | |
fn(element) | |
) | |
return resultArray |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment