ouroboros-consensus-0.28.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Util.AnchoredSeq

Description

Utilities on AnchoredSeqs.

Synopsis

Documentation

takeLongestSuffix Source #

Arguments

∷ (Monoid s, Anchorable v a b) 
⇒ (AnchoredSeq v a b → s)

f: Compute a monoidal summary of a fragment.

→ (s → Bool)

p: Predicate on the summary of a fragment.

AnchoredSeq v a b

Input sequence as.

AnchoredSeq v a b

A suffix of the input sequence.

Take the longest suffix of an AnchoredSeq as satisfying the given predicate p on the monoidal summary given by f.

TODO: upstream this function

PRECONDITIONS:

For as0, as1 such that AS.join as0 as1 = Just as2, we must have the following homomorphism property:

f as0 <> f as1 ≡ f as2

For empty ase, we must have f ase ≡ mempty.

The predicate must be monotonic, ie when suf0 is a suffix of as and suf1 is a suffix of suf0, then p (f suf0) must imply p (f suf1). Furthermore, we must have p mempty.