예제 #1
0
파일: FuturePool.py 프로젝트: dhobbs/cljppy
    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
파일: test_core.py 프로젝트: dhobbs/cljppy
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
파일: test_core.py 프로젝트: dhobbs/cljppy
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
파일: generators.py 프로젝트: dhobbs/cljppy
def __ipowers_of(n):
    """
    Lazily returns all powers of n, starting with 1
    """
    return iterate(partial(mult, n), 1)
예제 #8
0
파일: generators.py 프로젝트: dhobbs/cljppy
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)