def r_map_really_tail(fn, arg): aux = tail_fnc(lambda arg: pattern_match(( (pair(identity, is_none), lambda arr: aux([arr[0], []])), ( pair(hd_tl_partial(identity, is_blank), identity), lambda arr: arr[1] + [fn(arr[0][0])] ), ( pair(hd_tl_partial(identity, identity), identity), lambda arr: aux([arr[0][1], arr[1] + [fn(arr[0][0])]]) ), ), arg)) return aux([arg, None])
from pyfunc.curry import curry_n from pyfunc.pattern_match import ( pattern_match, hd_tl_partial, is_blank, identity, match_curry, ) r_map = lambda fn, arg: pattern_match(( (hd_tl_partial(identity, is_blank), lambda arr: [fn(arr[0])]), ( hd_tl_partial(identity, identity), lambda arr: [fn(arr[0])] + r_map(fn, arr[1]) ), ), arg) r_map_curry = curry_n(r_map, 2) twice = r_map_curry(lambda x: x * 2) is_none = match_curry(lambda obj: obj is None) pair = lambda match_x, match_y: lambda arr: (match_x(arr[0]), match_y(arr[1])) def r_map_tail(fn, arg): aux = lambda arg: pattern_match(( (pair(identity, is_none), lambda arr: aux([arr[0], []])), ( pair(hd_tl_partial(identity, is_blank), identity), lambda arr: arr[1] + [fn(arr[0][0])] ), ( pair(hd_tl_partial(identity, identity), identity), lambda arr: aux([arr[0][1], arr[1] + [fn(arr[0][0])]])