Skip to content

Commit c93c58b

Browse files
committed
0.0.27
1 parent a953daf commit c93c58b

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

Changes

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Revision history for String-Utils
22

33
{{$NEXT}}
44

5+
0.0.27 2024-08-18T12:20:10+02:00
6+
- Add support for ":Pair" named argument to "paragraphs" to set
7+
the class with which to create the objects
8+
59
0.0.26 2024-08-16T13:53:24+02:00
610
- Add support for "regexify"
711

META6.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
],
3131
"test-depends": [
3232
],
33-
"version": "0.0.26"
33+
"version": "0.0.27"
3434
}

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ Lazily produces a `Seq` of `Pairs` with paragraphs from a `Seq` or string in whi
360360

361361
The optional second argument can be used to indicate the ordinal number of the first line in the string.
362362

363+
```raku
364+
my class A is Pair { }
365+
.say for paragraphs("a\n\nb", 1, :Pair(A)); # 1 => a␤3 => b␤
366+
```
367+
368+
Also takes an optional named argument `:Pair` that indicates the class with which the objects should be created. This defailts to the core `Pair` class.
369+
363370
regexify
364371
--------
365372

doc/String-Utils.rakudoc

+11
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ and the value is the paragraph (without trailing newline).
423423
The optional second argument can be used to indicate the ordinal number
424424
of the first line in the string.
425425

426+
=begin code :lang<raku>
427+
428+
my class A is Pair { }
429+
.say for paragraphs("a\n\nb", 1, :Pair(A)); # 1 => a␤3 => b␤
430+
431+
=end code
432+
433+
Also takes an optional named argument C<:Pair> that indicates the class
434+
with which the objects should be created. This defailts to the core
435+
C<Pair> class.
436+
426437
=head2 regexify
427438

428439
=begin code :lang<raku>

lib/String/Utils.rakumod

+8-6
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,17 @@ my sub all-same(str $string) {
396396
}
397397

398398
my proto sub paragraphs(|) {*}
399-
my multi sub paragraphs(@source, Int:D $initial = 0) {
399+
my multi sub paragraphs(@source, Int:D $initial = 0, :$Pair = Pair) {
400400
my class Paragraphs does Iterator {
401401
has $!iterator;
402402
has int $!line;
403+
has $!Pair;
403404

404-
method new($iterator, int $line) {
405+
method new($iterator, int $line, $Pair) {
405406
my $self := nqp::create(self);
406407
nqp::bindattr( $self,Paragraphs,'$!iterator',$iterator);
407408
nqp::bindattr_i($self,Paragraphs,'$!line', $line - 1);
409+
nqp::bindattr( $self,Paragraphs,'$!Pair', $Pair);
408410
$self
409411
}
410412

@@ -419,7 +421,7 @@ my multi sub paragraphs(@source, Int:D $initial = 0) {
419421
my sub paragraph() {
420422
$!line = $line;
421423

422-
Pair.new(
424+
$!Pair.new(
423425
$line - nqp::elems($collected),
424426
nqp::join("\n", $collected)
425427
)
@@ -456,10 +458,10 @@ my multi sub paragraphs(@source, Int:D $initial = 0) {
456458
}
457459

458460
# Produce the sequence
459-
Seq.new: Paragraphs.new(@source.iterator, $initial)
461+
Seq.new: Paragraphs.new(@source.iterator, $initial, $Pair)
460462
}
461-
my multi sub paragraphs(Cool:D $string, Int:D $initial = 0) {
462-
paragraphs $string.Str.lines, $initial
463+
my multi sub paragraphs(Cool:D $string, Int:D $initial = 0, :$Pair = Pair) {
464+
paragraphs $string.Str.lines, $initial, :$Pair
463465
}
464466

465467
my sub regexify(str $spec, *%_) {

0 commit comments

Comments
 (0)