def handleFile(consumer, fileName): def _go(writer): with open(fileName, "rt") as f: return reduce(writer, [consumer(x.strip()) for x in f.readlines() if x], 0) if not path.exists(fileName): return 300 return _go(partial(writeErrand, firstOrNone(*path.splitext(fileName)) )) and 0
def finderFunc(ff, *arguments): def extr(kw, f): if kw in arguments: return partial(f,_xtractKey(*arguments[arguments.index(kw):])) return None return firstOrNone(*filter(None, [extr('limit', lambda l,x: ff.find(x).limit(int(l))), extr('skip', lambda o,x: ff.find(x).skip(int(o))), ff.find]))
def bytesOf(stream): '''Could not read data from stream.''' return firstOrNone(*mchain(stream, "read", "close"))
def linesOf(stream): # rig:3 '''Could not read lines out of stream.''' return firstOrNone(*mchain(stream, "readlines", "close"))
def firstGood(*streams): '''Did not receive any good byte streams.''' return firstOrNone(*filter(goodStream, streams))
def writeTo(lines, stream): # rig:3 '''Unable to write to stream.''' return goodStream(stream) and firstOrNone(stream.writelines(lines) is None, stream.close())