Iterator of infinite dice rolls.
        :param count: [0] Return list of ``count`` sums
        :param func: [sum] Apply func to list of individual die rolls func([])
513962
def iter(self, count=0, func=sum):
        '''
        '''
        while True:
            yield self.roll(count, func)
1346547
def wrap(self, func):
        
        @six.wraps(func)
        def wrapper(*args, **kwargs):
            try:
                return self.aggregate()
            except KeyError:
                return func(*args, **kwargs)
        return wrapper
229283
def _repeat(self, count, func):
        
        if count != 1:
            with self._qpart:
                for _ in range(count):
                    func()
        else:
            func()
1082076
def x_rolls(self, number, count=0, func=sum):
        '''
        '''
        for x in range(number):
            yield self.roll(count, func)
1074609
def count(self):
        
        return (
            self
            .mapPartitions(lambda p: [sum(1 for _ in p)])
            .reduce(operator.add)
        )
1021495
def count_generator(generator, memory_efficient=True):
    
    if memory_efficient:
        counter = 0
        for _ in generator:
            counter += 1
        return counter
    else:
        return len(list(generator))
326011
def generate_func(self, table):
        

        # Ensure that `self` isn't suddenly in the closure...
        n = self.n

        def func(word):
            return sum(x * ord(c) for x, c in zip(table, word)) % n

        return func
797743
def getCountKwargs(func):
    
    # Get all arguments of the function
    if hasattr(func, "__code__"):
        func_args = func.__code__.co_varnames[:func.__code__.co_argcount]
        for pair in validCountKwargs:
            if ( pair[0] in func_args and pair[1] in func_args ):
                return pair
    # else
    return None
106575
def lambda_tuple_converter(func):
    
    if func is not None and func.__code__.co_argcount == 1:
        return lambda *args: func(args[0] if len(args) == 1 else args)
    else:
        return func
131520
def head_while(self, func: Callable[[T], bool]) -> 'TList[T]':
        
        r = TList()
        for x in self:
            if not func(x):
                return r
            else:
                r.append(x)
        return r
103186
def sum_dice(spec):
    
    if spec[0] == 'c': return spec[1]
    elif spec[0] == 'r': return sum(spec[1])
    elif spec[0] == 'x':
        return [sum_dice(r) for r in spec[1]]
    elif spec[0] in ops:
        return (spec[0], sum_dice(spec[1]), sum_dice(spec[2]))
    else: raise ValueError("Invalid dice specification")
1016759
def foreachPartition(self, f):
        
        def func(it):
            r = f(it)
            try:
                return iter(r)
            except TypeError:
                return iter([])
        self.mapPartitions(func).count()
405517
def each(iterable = None, *, name = None, metric = call_default):
    
    if iterable is None:
        return _each_decorator(name, metric)
    else:
        return _do_each(iterable, name, metric)
613242
def _total_counts(seqs, seqL, aligned=False):
    
    total = Counter()
    if isinstance(seqs, list):
        if not aligned:
            l = len([total.update(seqL[s].freq) for s in seqs])
        else:
            l = len([total.update(seqL[s].freq) for s in seqs if seqL[s].align > 0])
    elif isinstance(seqs, dict):
        [total.update(seqs[s].get_freq(seqL)) for s in seqs]
        l = sum(len(seqs[s].idmembers) for s in seqs)
    return total, l
381841
def _accumulate(iterable, func=(lambda a,b:a+b)): # this was from the itertools documentation
    ''
    # accumulate([1,2,3,4,5]) --> 1 3 6 10 15
    # accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120
    it = iter(iterable)
    try:
        total = next(it)
    except StopIteration:
        return
    yield total
    for element in it:
        total = func(total, element)
        yield total
889964
def _calc_odds(self):
        ''''''
        def recur(val, h, dice, combinations):
            for pip in dice[0]:
                tot = val + pip
                if len(dice) > 1:
                    combinations = recur(tot, h, dice[1:], combinations)
                else:
                    combinations += 1
                    h[tot] = h.get(tot, 0) + 1
            return combinations
        if self.summable:
            start = 0
        else:
            start = ''
        h = dict()
        funky = [d.values for d in self._dice]
        # count of possible results of rolling dice
        combinations = recur(start, h, funky, 0.0)
        self._odds = [(roll, h[roll], h[roll] / combinations) for roll in h.keys()]
        self._odds.sort()
1247990
def countByValue(self):
        
        return self.map(lambda x: (x, 1)).reduceByKey(lambda x, y: x+y)