Determine if a string has all unique characters: Difference between revisions

m
Line 1,159:
)
]))
return Just(second(fmap(fst))(
splitArrow(fst)(fmap(fst))sorted(
sorted(duplicates,
key=lambda kv: duplicates,kv[1][0]
key=lambda kv: kv[1])[0]
)) if duplicates else Nothing()[0]
)
) if duplicates else Nothing()
else:
return Nothing()
Line 1,263 ⟶ 1,261:
None is m or m.get('Nothing')
) else f(m.get('Just'))
 
 
# splitArrow (***)second :: (a -> b) -> ((c, -> da) -> ((ac, c) -> (b, d))
def splitArrowsecond(f):
'''A simple function lifted to a function over a tuple,
with f applied only the second of two values.
'''
return lambda g: lambda tplxy: (f(tplxy[0]), gf(tplxy[1]))
 
 
Line 1,269 ⟶ 1,275:
'''Second member of a pair.'''
return tpl[1]
 
 
# splitArrow (***) :: (a -> b) -> (c -> d) -> ((a, c) -> (b, d))
def splitArrow(f):
'''A tuple of (f(x), g(y)) derived
from (x, y)
'''
return lambda g: lambda tpl: (f(tpl[0]), g(tpl[1]))
 
 
9,659

edits