import functools, operator
from collections import defaultdict

def concat(sequences):
  return functools.reduce(operator.concat, sequences)

def lower_first(string):
  length = len(string)

  if length == 0: return ''
  if length == 1: return string.lower()
  else:           return string[0].lower() + string[1:]

def group_by(array, fun):
  result = defaultdict(list)

  for elem in array: result[fun(elem)].append(elem)

  return dict(result)

# so that we can call it as expression
def fail(error):
  raise error
