1#!/usr/bin/env python3
 2
 3"""Implementation of Sequencer class."""
 4
 5from collections import namedtuple
 6
 7Sequence = namedtuple('Sequence', 'first last count')
 8
 9
10class Sequencer:
11    """Ingest a list of objects and compile stats about them."""
12
13    def __init__(self, matcher):
14        self.matcher = matcher
15        self.first = None
16        self.prev = None
17        self.counter = None
18
19    def accept(self, obj):
20        """Ingest single value."""
21
22        result = None
23        if self.prev is not None:
24            if self.matcher(obj, self.prev):
25                # continue the sequence
26                self.counter += 1
27
28            else:
29                # flush and begin new sequence
30                result = Sequence(self.first, self.prev, self.counter)
31                self.first = obj
32                self.counter = 1
33
34        else:
35            self.first = obj
36            self.counter = 1
37
38        self.prev = obj
39        return result
40
41    def accept_many(self, iterable):
42        """Accept multiple objects."""
43        raise NotImplementedError()