示例#1
0
    def __init__(self, f, data, poolsize=cpu_count(), chunksize=512):
        self.__poolsize = poolsize
        self.__pool = []
        self.values = []
        self.__partitions = partition_all(chunksize, data)
        self.__position = 0
        self.realised = False
        self.all_work_delivered = False
        self.__partitions.realise_to(self.__poolsize)

        for _ in range(poolsize):
            self.__pool.append(FutureConsumer(partial(map, f)))

        self.dispatch()
        self.__blocking_thread = Thread(target=self.__block)
        self.__blocking_thread.daemon = True
        self.__blocking_thread.start()
示例#2
0
def test_doall():
    s = []
    fn_calls = repeatedly(partial(_side_effecter, s), 5)
    assert doall(fn_calls) == list(fn_calls)
    assert s == [0, 0, 0, 0, 0]
示例#3
0
def test_dorun():
    s = []
    assert dorun(repeatedly(partial(_side_effecter, s), 5)) is None
    assert s == [0, 0, 0, 0, 0]
示例#4
0
文件: test_fn.py 项目: dhobbs/cljppy
def test_juxt():
    assert juxt()(1, 2, 3) == []
    assert juxt(partial(plus, 1), partial(plus, -1))(1) == [2, 0]
    assert juxt(partial(plus, 1), partial(plus, -1))() == [1, -1]
示例#5
0
文件: test_fn.py 项目: dhobbs/cljppy
def test_comp():
    assert comp(partial(mult, 3), plus)(1, 2) == 9
    assert comp() == identity
示例#6
0
文件: test_fn.py 项目: dhobbs/cljppy
def test_partial():
    assert partial(plus)(1, 2, 3) == 6
    assert partial(plus, 1)(2, 3) == 6
    assert partial(take_last, 2)([1, 2, 3, 4]) == [3, 4]
    assert apply(partial, [plus, 1, 2, 3])() == 6
示例#7
0
def __ipowers_of(n):
    """
    Lazily returns all powers of n, starting with 1
    """
    return iterate(partial(mult, n), 1)
示例#8
0
def __inatural_numbers():
    """
    The natural numbers (starting with 0 of course).
    range is DEFINITELY preferable.. this is just a toy example
    """
    return iterate(partial(plus, 1), 0)