Skip to content

Instantly share code, notes, and snippets.

@ShimmerFairy
Created July 8, 2011 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShimmerFairy/1072463 to your computer and use it in GitHub Desktop.
Save ShimmerFairy/1072463 to your computer and use it in GitHub Desktop.
comb patch
From 4090a881ad27c1e10192dd5522d963fc91f39520 Mon Sep 17 00:00:00 2001
From: lue <rnddim@gmail.com>
Date: Fri, 8 Jul 2011 11:30:50 -0700
Subject: [PATCH] Added comb method and subroutine.
---
src/core/Cool.pm | 11 +++++++++--
src/core/Str.pm | 9 ++++++++-
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/core/Cool.pm b/src/core/Cool.pm
index 75bb66c..95ad5db 100644
--- a/src/core/Cool.pm
+++ b/src/core/Cool.pm
@@ -20,10 +20,15 @@ my class Cool {
)
}
- method substr($start as Int, $length?) {
+ method substr($start as Int, $length?) {
self.Stringy.substr($start, $length);
}
+ proto method comb(|$) {*}
+ multi method comb(:$lim) {
+ self.Str.comb(:$lim);
+ }
+
method uc() {
nqp::p6box_s(nqp::uc(nqp::unbox_s(self.Str)))
}
@@ -47,7 +52,7 @@ my class Cool {
}
method chop() {
- self.Str.chop
+ self.Str.chop;
}
method ord() {
@@ -94,3 +99,5 @@ sub substr($s,$pos,$chars?) { $s.substr($pos,$chars) }
sub uc($s) { $s.uc }
sub ucfirst($s) { $s.ucfirst }
+proto sub comb(|$) {*}
+multi sub comb($s, :$lim) { $s.comb(:$lim) }
diff --git a/src/core/Str.pm b/src/core/Str.pm
index 64cd17c..3074dd7 100644
--- a/src/core/Str.pm
+++ b/src/core/Str.pm
@@ -39,7 +39,14 @@ my class Str does Stringy {
nqp::unbox_s(self),
nqp::unbox_i($start.Int),
nqp::unbox_i($length)));
- }
+ }
+
+ proto method comb(|$) {*}
+ multi method comb(:$lim) {
+ gather for 1..($lim//self.chars) {
+ take self.substr($_-1,1);
+ }
+ }
# chars used to handle ranges for pred/succ
my $RANGECHAR =
--
1.6.3.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment