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.139 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.138 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.137 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.136 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.135 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.134 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.133 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.132 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.131 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.130 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.129 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.128 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.127 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.126 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.125 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.124 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.123 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.122 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.121 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm
trackler-2.2.1.120 tracks/perl5/exercises/strain/.meta/solutions/Strain.pm