Sha256: 0a38bb56094f6dd286169ce5559673c4fb61b5d4b3c6560dec3be4b503444d87

Contents?: true

Size: 553 Bytes

Versions: 73

Compression:

Stored size: 553 Bytes

Contents

package Strain;

use strict;
use warnings;

sub keep { [ _filter(@_, 1) ] }
sub discard { [ _filter(@_, 0) ] }

sub _filter {
    my ($list, $function, $is_keeping) = @_;

    die "ArgumentError: 2nd parameter must be a function reference" unless ref $function eq 'CODE';

    my @result;

    foreach my $element (@$list) {
        if ($is_keeping) {
            push @result, $element if $function->($element);
            next;
        }
        # discard
        push @result, $element unless $function->($element);
    }

    return @result;
}

1;

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.179 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.178 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.177 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.176 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.175 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.174 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.173 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.172 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.171 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.170 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.169 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.167 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.166 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.165 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.164 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.163 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.162 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.161 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.160 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm