Skip to content

Commit

Permalink
1.32 - Added commands: sum, uniq.
Browse files Browse the repository at this point in the history
  • Loading branch information
Timofey Potapov committed Oct 30, 2024
1 parent 5f4194d commit 16ceeea
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
8 changes: 7 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
Revision history for e

=================
1.31 - 2024-10-
1.32 - 2024-10-30
=================

Added commands: sum, uniq.

=================
1.31 - 2024-10-13
=================

Improved Build.PL.
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
⠹⡽⣾⣿⠹⣿⣆⣾⢯⣿⣿ ⡞ ⠻⣿⣿⣿⠁ ⢠⣿⢏ ⡀ ⡟ ⢀⣴⣿⠃⢁⡼⠁ ⠈
⠈⠛ ⢻⣿⣧⢸⢟⠶⢾⡇ ⣸⡿⠁ ⢠⣾⡟⢼ ⣷ ⡇ ⣰⠋⠙⠁
⠈⣿⣻⣾⣦⣇⢸⣇⣀⣶⡿⠁⣀⣀⣾⢿⡇⢸ ⣟⡦⣧⣶⠏ unleashed
⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄ v1.31
⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄ v1.32
⢻⡄ ⠐⠚⠋⣠⡾⣧⣿⠁⠙⢳⣽⡟
⠈⠳⢦⣤⣤⣀⣤⡶⠛ ⠈⢿⡆ ⢿⡇
⠈ ⠈⠓ ⠈
Expand Down Expand Up @@ -442,7 +442,7 @@ Turn string into a [Mojo::File](https://metacpan.org/pod/Mojo%3A%3AFile) object.

$ perl -Me -e 'say r j f("hello.json")->slurp'

## Math Help
## List Support

### max

Expand All @@ -458,6 +458,22 @@ Get the smallest number in a list.
$ perl -Me -e 'say max 2,4,1,3'
1

### sum

Adds a list of numbers.

$ perl -Me -e 'say sum 1..10'
55

### uniq

Get the unique values in a list.

$ perl -Me -e 'say for uniq 2,4,4,6'
2
4
6

## Output

### say
Expand Down
47 changes: 43 additions & 4 deletions lib/e.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ package e;
⠹⡽⣾⣿⠹⣿⣆⣾⢯⣿⣿ ⡞ ⠻⣿⣿⣿⠁ ⢠⣿⢏ ⡀ ⡟ ⢀⣴⣿⠃⢁⡼⠁ ⠈
⠈⠛ ⢻⣿⣧⢸⢟⠶⢾⡇ ⣸⡿⠁ ⢠⣾⡟⢼ ⣷ ⡇ ⣰⠋⠙⠁
⠈⣿⣻⣾⣦⣇⢸⣇⣀⣶⡿⠁⣀⣀⣾⢿⡇⢸ ⣟⡦⣧⣶⠏ unleashed
⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄ v1.31
⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄ v1.32
⢻⡄ ⠐⠚⠋⣠⡾⣧⣿⠁⠙⢳⣽⡟
⠈⠳⢦⣤⣤⣀⣤⡶⠛ ⠈⢿⡆ ⢿⡇
⠈ ⠈⠓ ⠈
Expand All @@ -45,7 +45,7 @@ use 5.006;
use strict;
use warnings;

our $VERSION = '1.31';
our $VERSION = '1.32';

=head1 SYNOPSIS
Expand Down Expand Up @@ -468,7 +468,7 @@ Turn string into a L<Mojo::File> object.
=cut

=head2 Math Help
=head2 List Support
=head3 max
Expand All @@ -484,6 +484,22 @@ Get the smallest number in a list.
$ perl -Me -e 'say max 2,4,1,3'
1
=head3 sum
Adds a list of numbers.
$ perl -Me -e 'say sum 1..10'
55
=head3 uniq
Get the unique values in a list.
$ perl -Me -e 'say for uniq 2,4,4,6'
2
4
6
=cut

=head2 Output
Expand Down Expand Up @@ -942,7 +958,7 @@ sub import {
},

######################################
# Math Help
# List Support
######################################

max => sub {
Expand All @@ -961,6 +977,29 @@ sub import {
List::Util::min( @_ );
},

sum => sub {
if ( !$imported{$caller}{"List::Util"}++ ) {
require List::Util;
}

List::Util::sum( @_ );
},

uniq => sub {
if ( !$imported{$caller}{"List::Util"}++ ) {
require List::Util;
}

# Since uniq is missing in some recent versions.
if ( List::Util->can( "uniq" ) ) {
List::Util::uniq( @_ );
}
else {
my %h;
grep { !$h{$_}++ } @_;
}
},

######################################
# Output
######################################
Expand Down
21 changes: 14 additions & 7 deletions t/01-simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,25 @@ is
"f - basename";

######################################
# Math Help
# List Support
######################################

is
max(10,20,9,15),
20,
"max - sanity check";
max( 10, 20, 9, 15 ), 20,
"max - sanity check";

is
min(10,20,9,15),
9,
"min - sanity check";
min( 10, 20, 9, 15 ), 9,
"min - sanity check";

is
sum( 1 .. 10 ), 55,
"sum - sanity check";

is_deeply
[ uniq 2, 4, 4, 6 ],
[ 2, 4, 6 ],
"uniq - sanity check";

######################################
# Output
Expand Down

0 comments on commit 16ceeea

Please sign in to comment.