package List;

use warnings;
use strict;
require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw(first);
our $VERSION = 0.03;

sub first
{
    if( ref $_[0] eq 'CODE' )
    {
        return _first_pred( @_ );
    }
    elsif( ref $_[0] eq 'Regexp' )
    {
        return _first_regex( @_ );
    }
    else
    {
        die "First argument is not a coderef or regex\n";
    }
}

sub _first_pred
{
    my $pred = shift;
    for(@_)
    {
        return $_ if $pred->();
    }
    return;
}

sub _first_regex
{
    my $pred = shift;
    for(@_)
    {
        return $_ if $_ =~ $pred;
    }
    return;
}

1;