Arrayのメソッド増強について


#1

e$B@DLZ$G$9!#e(B

1.9 e$B$Ge(B String#each e$B$,$J$/$J$j$^$7$?$,!"$I$&$K$bITJX$G$9!#e(B
e$B$J$s$GITJX$J$N$+9M$($F$_$?$H$3$m!"e(BArray e$B$N%a%=%C%I$,e(B
String e$B$KHf$Y$F<e$$$N$,860x$G$O$J$$$+$H9M$($k$h$&$K$J$je(B
e$B$^$7$?!#$=$3$G!"0J2<$N$h$&$J%a%=%C%I$r?7$?$KF3F~$9$ke(B
e$B$3$H$rDs0F$7$^$9!#e(B

Enumerable#split(max = nil) {|item| }

each e$B$GF@$i$l$kMWAG$r=gHV$K%V%m%C%/$KEO$7!"%V%m%C%/$,e(B
e$B??$rJV$7$?$H$3$m$GJ,3d$7$F!"G[Ns$NG[Ns$rJV$9!#:GBge(B max
e$B8D$^$GJ,3d$9$k!#e(Bmax = nil e$B$N$H$-$OL5@)8B$KJ,3d$9$k!#e(B
(e$BHsGK2uE*e(B)

e$BNce(B
p [1, 2, 3, 4, 5].split {|i| i % 2 == 0 } #=> [[1], [3], [5]]

e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(Bbreake$B$r7+$jJV$7E,MQ$9$k>le(B
e$B9g$KAjEve(B

Enumerable#span {|item| }

e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9@hF,ItJ,$H;D$j$NItJ,$Ke(B
e$BJ,3d$7$Fe(B 2 e$BMWAG$NG[Ns$GJV$9!#e(B(e$BHsGK2uE*e(B)

e$BNce(B
p [1, 2, 3, 1, 2, 3].span {|item| item < 3 } # => [[1, 2], [3,
1, 2, 3]]

e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(Bspan

Array#take {|item| } e$BJLL>0F!'e(Btake_while, slice{}

e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9MWAG$r@hF,$+$ie(B
e$B$9$Y$F=8$a$FG[Ns$GJV$9!#e(B(e$BHsGK2uE*e(B)

e$BNce(B
p [1, 2, 3, 2, 1].take {|i| i < 3 } # => [1, 2]

e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(BtakeWhile

Array#drop {|item| } e$BJLL>0F!'e(Blstrip, drop_while,
reject_head

e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9MWAG$r@hF,$+$ie(B
e$B$9$Y$F=|$$$?;D$j$NG[Ns$rJV$9!#e(B(e$BHsGK2uE*e(B)

e$BNce(B
p [1, 2, 3, 4, 5].drop {|i| i < 3 } # => [3, 4, 5]

e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(BdropWhile

Array#reverse_drop {|item| } e$BJLL>0F!'e(Brstrip,
reject_tail, reject_last

e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9MWAG$rKvHx$+$ie(B
e$B$9$Y$F=|$$$?;D$j$NG[Ns$rJV$9!#e(B(e$BHsGK2uE*e(B)

e$BNce(B
p [1, 2, 3, 4, 5].reverse_drop {|i| i > 3 } # => [1, 2, 3]

Array#drop_both {|item| } e$BJLL>0F!'e(Bstrip

e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9MWAG$r@hF,$HKvHx$Ne(B
e$BN>J}$+$i$9$Y$F=|$$$?;D$j$NG[Ns$rJV$9!#e(B(e$BHsGK2uE*e(B)

e$BNce(B
p [1, 2, 3, 4, 3, 2, 1].drop_both {|i| i < 3 } # => [3, 4, 3]


#2

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message Re: [ruby-dev:30407] Arraye$B$N%a%=%C%IA}6/$K$D$$$Fe(B
on Sat, 24 Feb 2007 14:21:37 +0900, Minero A.
removed_email_address@domain.invalid writes:

|1.9 e$B$Ge(B String#each e$B$,$J$/$J$j$^$7$?$,!"$I$&$K$bITJX$G$9!#e(B
|e$B$J$s$GITJX$J$N$+9M$($F$_$?$H$3$m!"e(BArray e$B$N%a%=%C%I$,e(B
|String e$B$KHf$Y$F<e$$$N$,860x$G$O$J$$$+$H9M$($k$h$&$K$J$je(B
|e$B$^$7$?!#$=$3$G!"0J2<$N$h$&$J%a%=%C%I$r?7$?$KF3F~$9$ke(B
|e$B$3$H$rDs0F$7$^$9!#e(B

e$B;EMM$,4JC1$G!"L>A0$bG<F@$G$-$?e(Btakee$B$He(Bdrope$B$OAaB.e(Btrunke$B$K<h$j9~e(B
e$B$_$^$9!#;D$j$O$b$&$A$g$C$H9M$($^$7$g$&!#e(B

| Enumerable#split(max = nil) {|item| }
|
|each e$B$GF@$i$l$kMWAG$r=gHV$K%V%m%C%/$KEO$7!"%V%m%C%/$,e(B
|e$B??$rJV$7$?$H$3$m$GJ,3d$7$F!"G[Ns$NG[Ns$rJV$9!#:GBge(B max
|e$B8D$^$GJ,3d$9$k!#e(Bmax = nil e$B$N$H$-$OL5@)8B$KJ,3d$9$k!#e(B
|(e$BHsGK2uE*e(B)
|
|e$BNce(B
| p [1, 2, 3, 4, 5].split {|i| i % 2 == 0 } #=> [[1], [3], [5]]
|
|e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(Bbreake$B$r7+$jJV$7E,MQ$9$k>le(B
|e$B9g$KAjEve(B

String#splite$B$H$NN`?d$,8z$/$H$$$&OC$G$O$"$j$^$9$,!"5U$K0z?t%Qe(B
e$B%?!<%s$,$A$g$C$H0c$&$N$G:.Mp$7$=$&$J5$$b$7$^$9!#e(BStringe$B$O$b$&e(B
Enumerablee$B$re(Bincludee$B$7$F$$$J$$$N$GLdBj$J$$$N$+$J!)e(B

| Enumerable#span {|item| }
|
|e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9@hF,ItJ,$H;D$j$NItJ,$Ke(B
|e$BJ,3d$7$Fe(B 2 e$BMWAG$NG[Ns$GJV$9!#e(B(e$BHsGK2uE*e(B)
|
|e$BNce(B
| p [1, 2, 3, 1, 2, 3].span {|item| item < 3 } # => [[1, 2], [3,
|1, 2, 3]]
|
|e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(Bspan

e$B8D?ME*$K$O$3$NF0:n$Ke(Bspane$B$H$$$&L>A0$O0cOB46$,$"$k$N$G$9$,!#e(B
Haskelle$B$,:NMQ$7$F$$$k$J$iLdBj$J$$$N$+$J!)e(B

| Array#take {|item| } e$BJLL>0F!'e(Btake_while, slice{}
|
|e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9MWAG$r@hF,$+$ie(B
|e$B$9$Y$F=8$a$FG[Ns$GJV$9!#e(B(e$BHsGK2uE*e(B)
|
|e$BNce(B
| p [1, 2, 3, 2, 1].take {|i| i < 3 } # => [1, 2]
|
|e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(BtakeWhile

ary.take(n) # e$B:G=i$Ne(Bne$BMWAGe(B
ary.take{|x| cond(x)} # e$B>e5-$N;EMMe(B

e$B$G<BAu$7$^$7$?!#6a$$$&$A$Ke(B(e$B:#F|Cf!)e(B)e$B%3%_%C%H$7$^$9!#e(B

| Array#drop {|item| } e$BJLL>0F!'e(Blstrip, drop_while,
|reject_head
|
|e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9MWAG$r@hF,$+$ie(B
|e$B$9$Y$F=|$$$?;D$j$NG[Ns$rJV$9!#e(B(e$BHsGK2uE*e(B)
|
|e$BNce(B
| p [1, 2, 3, 4, 5].drop {|i| i < 3 } # => [3, 4, 5]
|
|e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(BdropWhile

takee$B$HF1MM!#$3$N%a%=%C%I$Oe(Bgeneratore$B$r;H$&$J$I$7$FCY1dI>2A$Ge(B
e$B$-$?$i$$$$$J$"$HL4A[$7$J$$$G$b$J$$$G$9$,!#e(B

| Array#reverse_drop {|item| } e$BJLL>0F!'e(Brstrip,
|reject_tail, reject_last
|
|e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9MWAG$rKvHx$+$ie(B
|e$B$9$Y$F=|$$$?;D$j$NG[Ns$rJV$9!#e(B(e$BHsGK2uE*e(B)
|
|e$BNce(B
| p [1, 2, 3, 4, 5].reverse_drop {|i| i > 3 } # => [1, 2, 3]

e$BL>A0$K0cOB46$,$"$j$^$9!#e(BString#rindexe$B$+$i$NN`?d$@$He(Brdrope$B$J$se(B
e$B$G$9$,e(Be$B!#e(B

| Array#drop_both {|item| } e$BJLL>0F!'e(Bstrip
|
|e$BG[Ns$NMWAG$N$&$A%V%m%C%/$,??$rJV$9MWAG$r@hF,$HKvHx$Ne(B
|e$BN>J}$+$i$9$Y$F=|$$$?;D$j$NG[Ns$rJV$9!#e(B(e$BHsGK2uE*e(B)
|
|e$BNce(B
| p [1, 2, 3, 4, 3, 2, 1].drop_both {|i| i < 3 } # => [3, 4, 3]

e$B$3$l$bL>A0$,!#e(Bstripe$B$C$F$N$bJ,$+$k$h$&$JJ,$+$i$J$$$h$&$J!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

#3

e$B:XF#$H?=$7$^$9!#e(BHaskelle$B$rCN$i$J$$AG?M$,$7$c$7$c$j=P$k$N$b$"$l$J$N$G$9e(B
e$B$,!"CN$i$J$$?M4V$H$7$F9M$($?$3$H$rEj9F$7$F$_$^$9!#e(B

On Mon, 26 Feb 2007 12:21:59 +0900
Yukihiro M. removed_email_address@domain.invalid wrote:

| Array#take {|item| } e$BJLL>0F!'e(Btake_while, slice{}

takee$B$@$H!C18l$H$7$FCj>]E*2a$.$J$$$G$7$g$&$+!#Cf?H$r!V<h$C$FMh$k!We(B
e$B%a%=%C%I$O4{B8$NCf$K$$$/$D$b$$j$^$9$7!#e(B

e$B$^$?!e(BHaskelle$B$rCN$i$J$$?M$K<h$C$F$ON`?d$b8z$+$J$$$H;W$$$^$9!#Nc$($Pe(B
take
e$BDI2C8e$Ke(BRubye$B$rJY6/$7$??M$,e(B fetch
e$B$bJY6/$7$?8e!$I$C$A$,$I$C$A$+J,$+$i$Je(B
e$B$/$J$j$=$&$G?4G[$G$9!#e(B

e$B2C$($F!V=EJ#$N$J$$e(Bselecte$B!W$H$$$&0UL#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$H$3$m$G$9!#e(B
takeWhile (<n) eieio => eiei
e$B$Ge(BHaskelle$B$@$H$A$c$s$H=EJ#e(Be$B$9$ke(Be$B$N$G!#e(B


#5

e$B@DLZ$G$9!#e(B

On 2007/02/26, at 14:09, Tadashi S. wrote:

e$B:XF#$H?=$7$^$9!#e(BHaskelle$B$rCN$i$J$$AG?M$,$7$c$7$c$j=P$k$Ne(B
e$B$b$"$l$J$N$G$9e(B
e$B$,!"CN$i$J$$?M4V$H$7$F9M$($?$3$H$rEj9F$7$F$_$^$9!#e(B

e$B$/$J$j$=$&$G?4G[$G$9!#e(B
e$B$G$O!e(Btake_while (e$B$G!%V%m%C%/IU$-$N$_e(B) e$B$J$i$I$&$G$9e(B
e$B$+!)e(B

| Array#drop {|item| } e$BJLL>0F!'e(Blstrip, drop_while,

e$B>e5-$Ne(Bselecte$B$H$NN`Hf$HF1$8$/!V=EJ#$N$J$$e(Brejecte$B!W$He(B
e$B8+$?;~!"$d$O$jJ,$+$j?Ie(B
e$B$$$H;W$$$^$9!#e(B

e$B>e5-e(B2e$B$D$N%V%m%C%/IU$-$NJ*$K$D$$$F$O!"@DLZ$5$s$Oe(B
ary.uniq.select {}
e$B$,D92a$.$ke(B(e$B8zN($b0-$=$&e(B)e$B$H$$$&0U8+$J$N$@$H?dB,$7$^e(B
e$B$7$?!#$G$7$?$ie(Bselect

e$B$$$(!"$=$l$O0c$$$^$9!#e(BArray#drop e$B$O=gHV$rJ]$C$?$^$^G[Ns$re(B
e$B=hM}$9$k$?$a$K;H$&%a%=%C%I$G$9!#Nc$($P%a!<%k$NJ8;zNs$re(B
e$B9TC10L$NJ8;zNsG[Ns$G;}$C$F$$$k$H$-!"e(B

body = lines.drop {|line| not line.strip.empty? }

e$B$H=q$/$H%a!<%kK\BNe(B (e$B$N:G=i$K%;%Q%l!<%?$N6u9T$,IU$$$?$be(B
e$B$Ne(B) e$B$,e(B
e$BF@$i$l$k$o$1$G$9!#e(B

e$B$^$"!"$3$N>l9g$Oe(B Array#split e$B$N$[$&$,L@$i$+$KJXMx$G!"e(B

header, body = lines.split(2) {|line| line.strip.empty? }

e$B$G%X%C%@$H%%G%#$,F@$i$l$^$9!#e(B


#6

e$B$3$s$P$s$O!":XF#$H?=$7$^$9!#e(B

On Mon, 26 Feb 2007 15:17:46 +0900
Minero A. removed_email_address@domain.invalid wrote:

| Array#take {|item| } e$BJLL>0F!'e(Btake_while, slice{}
(snip)
e$B$G$O!e(Btake_while (e$B$G!%V%m%C%/IU$-$N$_e(B) e$B$J$i$I$&$G$9e(B
e$B$+!)e(B

e$B$=$N8e!"<+J,$h$j3F8@8l$K>$7$/e(BHaskelle$B$bCN$C$F$$$kM?M$H5DO@$7$?$N$G$9e(B
e$B$,!"<+J,$be(B"take"e$B$K;?@.I<$rEj$8$h$&$H;W$$$^$9!#!V4JC1$J$b$N$O4JC1$K!W$He(B
e$B$$$&;v$G!#e(B

take(n)e$B$b!"$^$D$b$H$5$s$,%3%_%C%H$J$5$C$?$h$&$Ke(BEnumerablee$B$N%a%=%C%I$Ge(B
e$B$"$l$P!"$"$k$Y$-$@$H;W$$$^$9!#e(B

e$B$$$(!"$=$l$O0c$$$^$9!#e(BArray#drop e$B$O=gHV$rJ]$C$?$^$^G[Ns$re(B
e$B=hM}$9$k$?$a$K;H$&%a%=%C%I$G$9!#Nc$($P%a!<%k$NJ8;zNs$re(B
e$B9TC10L$NJ8;zNsG[Ns$G;}$C$F$$$k$H$-!"e(B

body = lines.drop {|line| not line.strip.empty? }

e$B$H=q$/$H%a!<%kK\BNe(B (e$B$N:G=i$K%;%Q%l!<%?$N6u9T$,IU$$$?$be(B
e$B$Ne(B) e$B$,e(B
e$BF@$i$l$k$o$1$G$9!#e(B

e$BKNIt$5$s$K$b$4;XE&$$$?$@$-$^$7$?$,!M}2r$7$^$7$?!#!V:G=i$+$i=gHV$K8+$F$$e(B
e$B$k!W$@$1$G$9$M!#$$j$,$H$&$4$6$$$^$9!#e(B

e$B$H$$$&$3$H$GAaB.!"e(BEnumerable#takee$B$N%I%-%e%a%s%H$X$N%Q%C%A$G$9!#e(B
e$B2C$($F!"e(Btake_i()/drop_i() e$B$NJQ?te(B n
e$B$OITMW$@$H;W$$$^$9!#e(B

Index: enum.c

enum.c (revision 11926)
+++ enum.c (working copy)
@@ -1224,8 +1224,6 @@
static VALUE
take_i(VALUE i, VALUE *arg)
{

  • long n = arg[1];
  • if (arg[1]-- == 0) rb_iter_break();
    rb_ary_push(arg[0], i);
    return Qnil;
    @@ -1250,8 +1248,8 @@
    *
    • a = [1, 2, 3, 4, 5]
      
    • a.take(3)             # => [4, 5]
      
    • a.take {|i| i < 3 }   # => [3, 4, 5]
      
    • a.take(3)             # => [1, 2, 3]
      
    • a.take {|i| i < 3 }   # => [1, 2]
      
    */

@@ -1278,8 +1276,6 @@
static VALUE
drop_i(VALUE i, VALUE *arg)
{

  • long n = arg[1];
  • if (arg[1] == 0) {
    rb_ary_push(arg[0], i);
    }

#7

e$B@DLZ$G$9!#e(B

On 2007/02/26, at 12:21, Yukihiro M. wrote:

e$B$_$^$9!#;D$j$O$b$&$A$g$C$H9M$($^$7$g$&!#e(B
e$B$"$j$,$H$&$4$6$$$^$9!#e(B

|e$BB>$N8@8l$G$NNc!'e(B Haskelle$B$Ne(Bbreake$B$r7+$jJV$7E,MQ$9$k>le(B
|e$B9g$KAjEve(B

String#splite$B$H$NN`?d$,8z$/$H$$$&OC$G$O$"$j$^$9$,!"5U$K0z?t%Qe(B
e$B%?!<%s$,$A$g$C$H0c$&$N$G:.Mp$7$=$&$J5$$b$7$^$9!#e(BStringe$B$Oe(B
e$B$b$&e(B
Enumerablee$B$re(Bincludee$B$7$F$$$J$$$N$GLdBj$J$$$N$+$J!)e(B

e$B$=$&$G$9$M$(!#3N$+$K<+J,$G=q$$$F$F$b$A$g$C$Hm4m0$7$^$7$?!#e(B

e$BAGD>$Ke(B break e$B$G$b$$$$$N$+$J$"!#$G$be(B Haskell e$B$@$He(B
span e$B$He(B break
e$B$,BP$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