From 1981fc9ce5b8b4a1c54cdf2b1ba8591d38b57296 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sat, 31 Oct 2026 19:07:39 +0200 Subject: [PATCH 1/9] feat: Create `Arrays::Simple` package --- src/lib/Utils/Arrays/Simple.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/lib/Utils/Arrays/Simple.pm diff --git a/src/lib/Utils/Arrays/Simple.pm b/src/lib/Utils/Arrays/Simple.pm new file mode 100644 index 0000000..9a2d670 --- /dev/null +++ b/src/lib/Utils/Arrays/Simple.pm @@ -0,0 +1,10 @@ +package Utils::Arrays::Simple; + +use strict; +use warnings; +use Exporter 'import'; + +1; + +__END__ + From f98a0874919b7044b66a69718ad147fa8774c943 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sat, 31 Oct 2026 19:11:52 +0200 Subject: [PATCH 2/9] feat: Implement basic array `union()` subroutine --- src/lib/Utils/Arrays/Simple.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib/Utils/Arrays/Simple.pm b/src/lib/Utils/Arrays/Simple.pm index 9a2d670..7117cb6 100644 --- a/src/lib/Utils/Arrays/Simple.pm +++ b/src/lib/Utils/Arrays/Simple.pm @@ -4,6 +4,29 @@ use strict; use warnings; use Exporter 'import'; +sub union { + my ($arr1, $arr2) = @_; + + my @res; + my %trackingHash; + + for my $element (@$arr1) { + if (not $trackingHash{$element}) { + $trackingHash{$element} = $element; + push @res, $element; + } + } + + for my $element (@$arr2) { + if (not $trackingHash{$element}) { + $trackingHash{$element} = $element; + push @res, $element; + } + } + + return @res; +} + 1; __END__ From d531e40ae799851af2d55ce243019056c91ad9b8 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sat, 31 Oct 2026 19:16:58 +0200 Subject: [PATCH 3/9] docs(src): Add comments to `union()` subroutine --- src/lib/Utils/Arrays/Simple.pm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lib/Utils/Arrays/Simple.pm b/src/lib/Utils/Arrays/Simple.pm index 7117cb6..6b8246e 100644 --- a/src/lib/Utils/Arrays/Simple.pm +++ b/src/lib/Utils/Arrays/Simple.pm @@ -5,29 +5,40 @@ use warnings; use Exporter 'import'; sub union { + # Parameters my ($arr1, $arr2) = @_; - my @res; + # Result array + my @union; + # Hash for tracking elements my %trackingHash; + # Loop through the first array for my $element (@$arr1) { + # If the element was not previously encountered if (not $trackingHash{$element}) { + # Add that element to the tracking hash $trackingHash{$element} = $element; - push @res, $element; + # Push the element to the result array + push @union, $element; } } + # Loop through the second array for my $element (@$arr2) { + # If the element was not previously encountered if (not $trackingHash{$element}) { + # Add that element to the tracking hash $trackingHash{$element} = $element; - push @res, $element; + # Push the element to the result array + push @union, $element; } } - return @res; + # Return the result array + return @union; } 1; __END__ - From 8521126614cdfd7beec80a2b00b4fb04da13d416 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sat, 31 Oct 2026 19:19:25 +0200 Subject: [PATCH 4/9] refactor: Improve `union()` logic --- src/lib/Utils/Arrays/Simple.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/Utils/Arrays/Simple.pm b/src/lib/Utils/Arrays/Simple.pm index 6b8246e..005aae0 100644 --- a/src/lib/Utils/Arrays/Simple.pm +++ b/src/lib/Utils/Arrays/Simple.pm @@ -14,22 +14,22 @@ sub union { my %trackingHash; # Loop through the first array - for my $element (@$arr1) { + foreach my $element (@$arr1) { # If the element was not previously encountered - if (not $trackingHash{$element}) { - # Add that element to the tracking hash - $trackingHash{$element} = $element; + if (not exists $trackingHash{$element}) { + # Add a truthy value for that element to the tracking hash + $trackingHash{$element} = 1; # Push the element to the result array push @union, $element; } } # Loop through the second array - for my $element (@$arr2) { + foreach my $element (@$arr2) { # If the element was not previously encountered - if (not $trackingHash{$element}) { - # Add that element to the tracking hash - $trackingHash{$element} = $element; + if (not exists $trackingHash{$element}) { + # Add a truthy value for that element to the tracking hash + $trackingHash{$element} = 1; # Push the element to the result array push @union, $element; } From ddc92d41c09f9bd7146b02417d733c6fad3dd2a6 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sat, 31 Oct 2026 19:30:38 +0200 Subject: [PATCH 5/9] docs: Update version numbers --- README.md | 2 +- meta/project.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 476073e..62e2b39 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Utility modules written in Perl, for Perl. - Author: Ethan Kletschke -- Version: `0.0.5` +- Version: `0.0.6` - Developed on: Ubuntu (WSL) - License: MIT - Project metadata file: [`project.yaml`](./meta/project.yaml) diff --git a/meta/project.yaml b/meta/project.yaml index bfcf027..641bcda 100644 --- a/meta/project.yaml +++ b/meta/project.yaml @@ -6,7 +6,7 @@ project-meta: - Perl status: Experimental license: MIT - version: 0.0.5 + version: 0.0.6 build: dev-environments: From b5c66afc5c0d941b360a83dc791b73a714d5a40b Mon Sep 17 00:00:00 2001 From: Ethan Date: Sun, 1 Nov 2026 06:27:03 +0200 Subject: [PATCH 6/9] fix(src): Export `union()` subroutine --- src/lib/Utils/Arrays/Simple.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/Utils/Arrays/Simple.pm b/src/lib/Utils/Arrays/Simple.pm index 005aae0..1fa625a 100644 --- a/src/lib/Utils/Arrays/Simple.pm +++ b/src/lib/Utils/Arrays/Simple.pm @@ -4,6 +4,10 @@ use strict; use warnings; use Exporter 'import'; +our @EXPORT_OK = qw( + union +); + sub union { # Parameters my ($arr1, $arr2) = @_; From f63f993a3c7c7ebab15140e6b08102cbc4214906 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sun, 1 Nov 2026 06:27:42 +0200 Subject: [PATCH 7/9] tests: Add `Arrays::Simple::union()` module test --- src/t/Arrays.t | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/t/Arrays.t diff --git a/src/t/Arrays.t b/src/t/Arrays.t new file mode 100644 index 0000000..0bc46d7 --- /dev/null +++ b/src/t/Arrays.t @@ -0,0 +1,25 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; + +use Utils::Arrays::Simple qw( + union +); + +subtest "Arrays::Simple" => sub { + subtest "union()" => sub { + my @arr1 = (1, 2, 3, 4); + my @arr2 = (3, 4, 5, 6); + + my @res = union(\@arr1, \@arr2); + + is_deeply(\@res, [1, 2, 3, 4, 5, 6], "Correctly determines the union"); + }; + + done_testing(); +}; + + +done_testing(); From 102e4602adf21ca21519f4ff971724e648c78f20 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sun, 1 Nov 2026 06:27:53 +0200 Subject: [PATCH 8/9] refactor: Remove redundant `use lib` --- src/t/TextFiles.t | 1 - 1 file changed, 1 deletion(-) diff --git a/src/t/TextFiles.t b/src/t/TextFiles.t index b09f5c4..ddfe62e 100644 --- a/src/t/TextFiles.t +++ b/src/t/TextFiles.t @@ -1,6 +1,5 @@ #!/usr/bin/env perl -use lib 'lib'; use strict; use warnings; use Test::More; From e0771401e801bf8884682c770da82a4c0e65d0e1 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sun, 1 Nov 2026 06:28:23 +0200 Subject: [PATCH 9/9] docs: Update `last-updated` --- meta/project.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta/project.yaml b/meta/project.yaml index 641bcda..ff0694d 100644 --- a/meta/project.yaml +++ b/meta/project.yaml @@ -1,7 +1,7 @@ project-meta: project-name: PerlUtils date-started: 2026-10-20 - last-updated: 2026-10-31 + last-updated: 2026-11-01 languages: - Perl status: Experimental