Skip to content

Instantly share code, notes, and snippets.

@selfsame
Created January 10, 2015 16:25
Show Gist options
  • Save selfsame/3655a3dc0f19010caf8b to your computer and use it in GitHub Desktop.
Save selfsame/3655a3dc0f19010caf8b to your computer and use it in GitHub Desktop.
def GET(col, k, notfound=None):
try: return col[k]
except: return notfound
def KEYFN(k):
def _KEYFN_(col, nf=None): return GET(col, k, nf)
return _KEYFN_
def NONE(v): return v is None
def NOT(v): return not v
def FIRST(col): return GET(col, 0)
def COMP(*args):
def _COMP_(v):
for f in args:
if not f(v): return False
return True
return _COMP_
def INVERT(*args):
def _INVERT_(x):
for f in args:
if f(x): return False
return True
return _INVERT_
_1 = "%1"
_2 = "%2"
_3 = "%3"
_4 = "%4"
_5 = "%5"
def INF(f, *args):
def _INF_(*_args): return apply(f, _SWAP(list(args), list(_args)))
return _INF_
def _SWAP(col, args):
for idx, v in enumerate(args):
w = GET([_1, _2, _3], idx)
if w in col:
widx = col.index(w)
col.remove(w)
col.insert(widx, v)
return col
print filter(INVERT(NONE), map(KEYFN("key"), [0, [], {"key":"found!"}]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment