def underride(a:tvstruct, b:tvstruct) -> tvstruct: answer = tvstruct(a) for k, v in b._nvs(): if k not in answer: answer[k] = v # answer._setdefault(k, v) # this doesn't respect insertion order!! return answer
def override(a:tvstruct, b:tvstruct) -> tvstruct: answer = tvstruct(a) answer._update(b._nvs()) return answer
def override(a:pydict, b:tvstruct) -> pydict: answer = dict(a) answer.update(b._nvs()) return answer
def sort(x: tvstruct) -> tvstruct: return tvstruct(sorted(x._nvs(), key=None, reverse=False))
def count(x:tvstruct) -> tCount: return len(x._names())
def select(pm: tvstruct, f2) -> tvstruct: filteredKVs = [] for k, v in pm._nvs(): if f2(k, v): filteredKVs.append((k, v)) return tvstruct(pm._t, filteredKVs)
def both(a:tvstruct, fn, b:tvstruct) -> pylist: return a._nvs() \ >> both \ >> (lambda aFV, bFV: fn(aFV[0], aFV[1], bFV[0], bFV[1])) \ >> b._nvs()