Toby Inkster avatar Toby Inkster committed 58502f5

faster implementation; release as 0.002

Comments (0)

Files changed (3)

lib/PerlX/Maybe.pm

 our (@EXPORT, @ISA);
 BEGIN {
 	$PerlX::Maybe::AUTHORITY = 'cpan:TOBYINK';
-	$PerlX::Maybe::VERSION   = '0.001';
+	$PerlX::Maybe::VERSION   = '0.002';
 	
 	require Exporter;
 	@ISA       = qw/Exporter/;
 
 sub maybe ($$@)
 {
-	my ($x, $y, @rest) = @_;
-	my @r = (
-		(defined $y && defined $x ? ($x, $y) : ()),
-		@rest,
-		);
-	return @r;
+	if (defined $_[0] and defined $_[1])
+	{
+		@_
+	}
+	else
+	{
+		(scalar @_ > 1) ? @_[2 .. $#_] : qw()
+	}
 }
 
 __FILE__
     defined $age ? (age => $age) : (),
     );
 
+or:
+
+ my $bob = Person->new(
+    (name => $name) x!!(defined $name),
+    (age  => $age)  x!!(defined $age),
+    );
+
 A slightly more elegant solution is the C<maybe> function:
 
 =head2 C<< maybe $x => $y, @rest >>

lib/Syntax/Feature/Maybe.pm

 
 BEGIN {
 	$Syntax::Feature::Maybe::AUTHORITY = 'cpan:TOBYINK';
-	$Syntax::Feature::Maybe::VERSION   = '0.001';
+	$Syntax::Feature::Maybe::VERSION   = '0.002';
 }
 
 sub install
 	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/PerlX-Maybe-0.001.tar.gz> ;
 	rdfs:label      "Initial release" .
 
+dist:project :release dist:v_0-002 .
+dist:v_0-002
+	a               :Version ;
+	dc:issued       "2012-05-03"^^xsd:date ;
+	:revision       "0.002"^^xsd:string ;
+	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/PerlX-Maybe-0.002.tar.gz> ;
+	dcs:changeset [
+		dcs:versus dist:v_0-001 ;
+		dcs:item   [ rdfs:label "Faster implementation. Tested on Perl 5.10.1 on Linux, the new version is 60% faster. (Not that it was slow to begin with - 'maybe' is a pretty simple function.)"@en ] ;
+		] .
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.