Exemples#

Programmation fonctionnelle#

  1. combiner or join

  2. filter

  3. mapper

  4. mapper

  5. reducer

  6. take

combiner or join

<<<

from sparkouille.fctmr import combiner


def c0(el):
    return el[0]


ens1 = [('a', 1), ('b', 2), ('a', 3)]
ens2 = [('a', 10), ('b', 20), ('a', 30)]
res = combiner(c0, ens1, c0, ens2)
print(list(res))

>>>

    [(('a', 1), ('a', 10)), (('a', 1), ('a', 30)), (('a', 3), ('a', 10)), (('a', 3), ('a', 30)), (('b', 2), ('b', 20))]

(entrée originale : simplefctmr.py:docstring of sparkouille.fctmr.simplefctmr.combiner, line 14)

filter

<<<

from sparkouille.fctmr import ffilter
res = ffilter(lambda x: x % 2 == 0, [4, 5])
print(list(res))

>>>

    [4]

(entrée originale : simplefctmr.py:docstring of sparkouille.fctmr.simplefctmr.ffilter, line 7)

mapper

<<<

from sparkouille.fctmr.pyparallel_fctmr import pyparallel_mapper
res = pyparallel_mapper(lambda x: x + 1, [4, 5])
print(list(res))

>>>

    /usr/local/lib/python3.9/multiprocessing/pool.py:265: ResourceWarning: unclosed running multiprocessing pool <multiprocessing.pool.ThreadPool state=RUN pool_size=8>
      _warn(f"unclosed running multiprocessing pool {self!r}",
    ResourceWarning: Enable tracemalloc to get the object allocation traceback
    [5, 6]

(entrée originale : pyparallel_fctmr.py:docstring of sparkouille.fctmr.pyparallel_fctmr.pyparallel_mapper, line 13)

mapper

<<<

from sparkouille.fctmr import mapper
res = mapper(lambda x: x + 1, [4, 5])
print(list(res))

>>>

    [5, 6]

(entrée originale : simplefctmr.py:docstring of sparkouille.fctmr.simplefctmr.mapper, line 7)

reducer

<<<

from sparkouille.fctmr import reducer
res = reducer(lambda x: x[0], [
              ('a', 1), ('b', 2), ('a', 3)], asiter=False)
print(list(res))

>>>

    [('a', [('a', 1), ('a', 3)]), ('b', [('b', 2)])]

(entrée originale : simplefctmr.py:docstring of sparkouille.fctmr.simplefctmr.reducer, line 11)

take

<<<

from sparkouille.fctmr import take
res = take([4, 5, 6, 7, 8, 9], 2, 2)
print(list(res))

>>>

    [6, 7]

(entrée originale : simplefctmr.py:docstring of sparkouille.fctmr.simplefctmr.take, line 8)