Skip to content

Commit

Permalink
implemented Þ, ÐṂ, ÐṀ for dyads
Browse files Browse the repository at this point in the history
  • Loading branch information
kckennylau authored and DennisMitchell committed May 9, 2017
1 parent 10777b5 commit 4f93f63
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions jelly.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ def equal(array):
return int(all(item == array[0] for item in array))

def extremes(min_or_max, link, array):
array = iterable(array, make_range=True)
if not array:
x,y = array
x = iterable(x, make_range=True)
if not x:
return []
results = [monadic_link(link, x) for x in array]
results = [variadic_link(link, (t, y)) for t in x]
best = min_or_max(results)
return [x for x, fx in zip(array, results) if fx == best]
return [t for t, ft in zip(x, results) if ft == best]

def flatten(argument):
flat = []
Expand Down Expand Up @@ -2445,15 +2446,15 @@ def zip_ragged(array):
'ÐṂ': attrdict(
condition = lambda links: links,
quicklink = lambda links, outmost_links, index: [attrdict(
arity = 1,
call = lambda z: extremes(min, links[0], z)
arity = links[0].arity,
call = lambda x, y = None: extremes(min, links[0], (x, y))
)]
),
'ÐṀ': attrdict(
condition = lambda links: links,
quicklink = lambda links, outmost_links, index: [attrdict(
arity = 1,
call = lambda z: extremes(max, links[0], z)
arity = links[0].arity,
call = lambda x, y = None: extremes(max, links[0], (x, y))
)]
),
}
Expand Down Expand Up @@ -2484,8 +2485,8 @@ def zip_ragged(array):
call = lambda x, y = None: [variadic_link(link, (t, y)) for t in iterable(x, make_range = True)]
),
'Þ': lambda link, none = None: attrdict(
arity = 1,
call = lambda x: sorted(x, key=lambda t: monadic_link(link, t))
arity = link.arity,
call = lambda x, y = None: sorted(x, key=lambda t: variadic_link(link, (t, y)))
),
'þ': lambda link, none = None: attrdict(
arity = 2,
Expand Down

0 comments on commit 4f93f63

Please sign in to comment.