<commit_before>import ray


class ActorPool:
    """Utility class to operate on a fixed pool of actors.

    Arguments:
        actors (list): List of Ray actor handles to use in this pool.

    Examples:
        >>> a1, a2 = Actor.remote(), Actor.remote()
        >>> pool = ActorPool([a1, a2])
        >>> print(pool.map(lambda a, v: a.double.remote(v), [1, 2, 3, 4]))
        [2, 4, 6, 8]
    """

    def __init__(self, actors):
        # actors to be used
        self._idle_actors = list(actors)

        # get actor from future
        self._future_to_actor = {}

        # get future from index
        self._index_to_future = {}

        # next task to do
        self._next_task_index = 0

        # next task to return
        self._next_return_index = 0

        # next work depending when actors free
        self._pending_submits = []

    def map(self, fn, values):
        """Apply the given function in parallel over the actors and values.

        This returns an ordered iterator that will return results of the map
        as they finish. Note that you must iterate over the iterator to force
        the computation to finish.

        Arguments:
            fn (func): Function that takes (actor, value) as argument and
                returns an ObjectRef computing the result over the value. The
                actor will be considered busy until the ObjectRef completes.
            values (list): List of values that fn(actor, value) should be
                applied to.

        Returns:
            Iterator over results from applying fn to the actors and values.

        Examples:
            >>> pool = ActorPool(...)
            >>> print(pool.map(lambda a, v: a.double.remote(v), [1, 2, 3, 4]))
            [2, 4, 6, 8]
        """
        for v in values:
            self.submit(fn, v)
        while self.has_next():
            yield self.get_next()

    def map_unordered(self, fn, values):
        """Similar to map(), but returning an unordered iterator.

        This returns an unordered iterator that will return results of the map
        as they finish. This can be more efficient that map() if some results
        take longer to compute than others.

        Arguments:
            fn (func): Function that takes (actor, value) as argument and
                returns an ObjectRef computing the result over the value. The
                actor will be considered busy until the ObjectRef completes.
            values (list): List of values that fn(actor, value) should be
                applied to.

        Returns:
            Iterator over results from applying fn to the actors and values.

        Examples:
            >>> pool = ActorPool(...)
            >>> print(pool.map(lambda a, v: a.double.remote(v), [1, 2, 3, 4]))
            [6, 2, 4, 8]
        """
        for v in values:
            self.submit(fn, v)<commit_msg>[Doc] Fix errors in ActorPool documentation (#10410)<commit_after>import ray


class ActorPool:
    """Utility class to operate on a fixed pool of actors.

    Arguments:
        actors (list): List of Ray actor handles to use in this pool.

    Examples:
        >>> a1, a2 = Actor.remote(), Actor.remote()
        >>> pool = ActorPool([a1, a2])
        >>> print(list(pool.map(lambda a, v: a.double.remote(v),\
        ...                     [1, 2, 3, 4])))
        [2, 4, 6, 8]
    """

    def __init__(self, actors):
        # actors to be used
        self._idle_actors = list(actors)

        # get actor from future
        self._future_to_actor = {}

        # get future from index
        self._index_to_future = {}

        # next task to do
        self._next_task_index = 0

        # next task to return
        self._next_return_index = 0

        # next work depending when actors free
        self._pending_submits = []

    def map(self, fn, values):
        """Apply the given function in parallel over the actors and values.

        This returns an ordered iterator that will return results of the map
        as they finish. Note that you must iterate over the iterator to force
        the computation to finish.

        Arguments:
            fn (func): Function that takes (actor, value) as argument and
                returns an ObjectRef computing the result over the value. The
                actor will be considered busy until the ObjectRef completes.
            values (list): List of values that fn(actor, value) should be
                applied to.

        Returns:
            Iterator over results from applying fn to the actors and values.

        Examples:
            >>> pool = ActorPool(...)
            >>> print(list(pool.map(lambda a, v: a.double.remote(v),\
            ...                     [1, 2, 3, 4])))
            [2, 4, 6, 8]
        """
        for v in values:
            self.submit(fn, v)
        while self.has_next():
            yield self.get_next()

    def map_unordered(self, fn, values):
        """Similar to map(), but returning an unordered iterator.

        This returns an unordered iterator that will return results of the map
        as they finish. This can be more efficient that map() if some results
        take longer to compute than others.

        Arguments:
            fn (func): Function that takes (actor, value) as argument and
                returns an ObjectRef computing the result over the value. The
                actor will be considered busy until the ObjectRef completes.
            values (list): List of values that fn(actor, value) should be
                applied to.

        Returns:
            Iterator over results from applying fn to the actors and values.

        Examples:
            >>> pool = ActorPool(...)
            >>> print(list(pool.map_unordered(lambda a, v: a.double.remote(v),\
            ...                               [1, 2, 3, 4])))
            [6, 2, 4, 8]
        """
        for v in values:
            self.submit(fn, v)
{'fraction_non_alphanumeric': 0.08753360215053764, 'fraction_numerical': 0.010920698924731184, 'mean_word_length': 1.7791783380018673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7194972', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1496, 'n_words': 657}