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