def _get_linkage_function(linkage):
    """
    >>> "f_linkage" in str(_get_linkage_function(0.5))
    True
    >>> "i_linkage" in str(_get_linkage_function(2))
    True
    >>> any is _get_linkage_function('single')
    True
    >>> all is _get_linkage_function('complete')
    True
    >>> ff = _get_linkage_function(0.5)
    >>> ff([True, False, False])
    False
    >>> ff([True, True, False])
    True
    >>> fi = _get_linkage_function(3)
    >>> fi([True, False, False])
    False
    >>> fi([True, True, False])
    False
    >>> fi([True, True, True]) and fi([True] * 10)
    True
    >>> _get_linkage_function('complete') == all == _get_linkage_function(1.0)
    True
    >>> _get_linkage_function(1) == any
    True
    """
    if linkage == 'single':
        return any

    if linkage == 'complete':
        return all

    if isinstance(linkage, float):
        assert 0 < linkage <= 1
        if linkage == 1:
            return all

        def f_linkage(bools, p=linkage):
            v = list(bools)
            if len(v) == 0: return False
            return (sum(v) / float(len(v))) >= p
        return f_linkage

    if isinstance(linkage, int):
        assert linkage >= 1
        if linkage == 1:
            return any

        def i_linkage(bools, n=linkage):
            v = list(bools)
            return sum(v) >= min(len(v), n)
        return i_linkage