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.159 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.158 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.157 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.156 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.155 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.154 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.153 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.152 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.151 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.150 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.149 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.148 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.147 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.146 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.145 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.144 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.143 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.142 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.141 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.140 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm