Conditional Independence Net

This website uses Javascript to render markdown documents in your browser, apply syntax highlighting to code fragments and render $\LaTeX$ formulas. Below is the markdown source code of this page. You can either read that or enable Javascript to have it rendered to HTML.

# NAME

CInet::Seq::Uniq - Lazy stringy uniq on a Seq object

# SYNOPSIS

    # Can use $_ or @_ in sub
    my $uniq = $seq->uniq;

    # Default stringification:
    my $uniq = $seq->uniq(sub{ "". $_ });

# DESCRIPTION

This class adapts a given [CInet::Seq](/doc/CInet%3A%3ASeq) object by filtering its elements
for uniqness. It returns only the first element with a given stringification.
The stringification by default is `"". $_` but can be overridden.
The implementation uses a hash to keep track of which strings were seen.
This cache is cleared immediately after the sequence is exhausted, before
the final `undef` is returned.

This class implements the [CInet::Seq](/doc/CInet%3A%3ASeq) role.

### new

    my $uniq = CInet::Seq::Uniq->new($source, $stringify);

Constructs a CInet::Seq::Uniq object which pulls its elements from
the `$source` Seq and only forwards the first element with a given
stringification to the consumer.

The stringification is given by the `$stringify` coderef but defaults
to `"". $_`.

The coderef can refer to its argument as either `$_` or via `@_`.

## Implementation of CInet::Seq

### next

    my $elt = $seq->next;
    last if not defined $elt;

Pull elements from the source Seq until the first time one of them
has a hitherto unknown stringification. Return either that element
or `undef` if the source is exhausted in the process.

The cache of seen strings is cleared immediately after the source
is exhausted.

# AUTHOR

Tobias Boege <tobs@taboege.de>

# COPYRIGHT AND LICENSE

This software is copyright (C) 2020 by Tobias Boege.

This is free software; you can redistribute it and/or
modify it under the terms of the Artistic License 2.0.