Skip to content

Commit 78a7f2c

Browse files
committed
Document PositionalBindFailover
Also cleanup type-graph.txt a bit, and remove outdated class names from the Cool documentation
1 parent f6fb0ef commit 78a7f2c

File tree

3 files changed

+61
-14
lines changed

3 files changed

+61
-14
lines changed

lib/Type/Cool.pod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ C<Int> converts the integer to C<Str> first.
2020
The following built-in types inherit from C<Cool>:
2121
L<Array> L<Backtrace> L<Bag> L<Baggy> L<Bool> L<Complex> L<Cool>
2222
L<Duration> L<Enumeration> L<EnumMap> L<FatRat> L<Hash> L<Instant>
23-
L<Int> L<Iterable> L<Iterator> L<KeyHash> L<KeySet> L<List>
24-
L<ListIter> L<LoL> L<MapIter> L<Nil> L<Num> L<Numeric> L<Parcel>
23+
L<Int> L<KeyHash> L<KeySet> L<List>
24+
L<Nil> L<Num> L<Numeric> L<Parcel>
2525
L<Range> L<Real> L<Seq> L<Set> L<Stash> L<Str> L<Stringy>
2626
2727
The following table summarizes the methods that C<Cool> provides, and

lib/Type/PositionalBindFailover.pod

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=begin pod
2+
3+
=TITLE role PositionalBindFailover
4+
5+
=SUBTITLE Failover for binding an Iterable to a Positional
6+
7+
role PositionalBindFailover { ... }
8+
9+
This role provides an interface by which an L<Iterable|/type/Iterable> can
10+
be coerced into a L<Positional|/type/Positional>, so that you can for example
11+
write:
12+
13+
sub fifths (@a) { # @a is constraint to Positional
14+
@a[4];
15+
}
16+
my $seq := gather { # a Seq, which is not Positional
17+
take $_ for 1..*;
18+
}
19+
say fifths($seq); # 5
20+
21+
The invocation of C<fifths> in the example above would oridinarly give a type
22+
error, because C<$seq> is of type L<Seq|/type/Seq>, whhich doesn't do the
23+
L<Positional|/type/Positional> interface that the C<@>-sigil implies.
24+
25+
But the signature binder recognizes that C<Seq> does the
26+
C<PositionalBindFailover> role, and calls its C<cache> method to coerce it to
27+
a L<List|/type/List>, which does the C<Positional> role.
28+
29+
30+
=head1 Methods
31+
32+
=head2 method cache
33+
34+
method cache(PositionalBindFailover:D:) returns List:D
35+
36+
Returns a L<List|/type/List> based on the C<iterator> method, and caches it.
37+
Subsequent calls to C<cache> always return the same C<List> object.
38+
39+
=head2 method list
40+
41+
method list(PositionalBindFailover:D:) returns List:D
42+
43+
Returns a L<List|/type/List> based on the C<iterator> method without caching it.
44+
45+
=head2 method iterator
46+
47+
method iterator(PositionalBindFailover:D:) { ... }
48+
49+
This method stub ensure that a class implementing role
50+
C<PositionalBindFailover> provides an C<iterator> method.
51+
52+
=end pod

type-graph.txt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Variable is Any
5858
class Proxy is Any
5959
class Cool is Any
6060
class Bool is Cool
61+
class Nil is Cool
6162

6263
[Basic]
6364
# Callables
@@ -186,26 +187,20 @@ class Thread
186187

187188
[Composite]
188189
# Collections: Iteration
189-
class Iterable is Any
190-
class Iterator is Iterable
191-
# Nil maybe should be a Basic type?
192-
class Nil is Iterator is Cool
193-
class GatherIter is Iterator
194-
class ListIter is Iterator
195-
class MapIter is Iterator
196-
class HashIter is Iterator
190+
role Iterable
191+
role Iterator
192+
role PositionalBindFailover
193+
class Seq is Cool does Iterable does PositionalBindFailover
197194

198195
[Composite]
199196
# Collections: Positional
200197
role Positional[::T = Mu]
201198
role Blob[::T = uint8] does Positional[T] does Stringy
202199
role Buf[::T = uint8] does Blob[T]
203200
class Capture
204-
class Parcel is Cool does Positional
205-
class Range is Iterable is Cool does Positional
206-
class List is Iterable is Cool does Positional
201+
class Range is Cool does Positional does Iterable
202+
class List is Cool does Positional does Iterable
207203
class Array is List
208-
class LoL is List
209204
role TypedArray[::TValue] does Positional[TValue]
210205

211206
[Composite]

0 commit comments

Comments
 (0)