Skip to content

Commit

Permalink
Streamline Map/Hash.gist a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jan 8, 2019
1 parent f010ef5 commit 225d2f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 6 additions & 10 deletions src/core/Hash.pm6
Expand Up @@ -195,16 +195,12 @@ my class Hash { # declared in BOOTSTRAP
}

multi method gist(Hash:D:) {
self.gistseen(self.^name, {
'{' ~
self.sort.map({
state $i = 0;
++$i == 101 ?? '...'
!! $i == 102 ?? last()
!! .gist
}).join(', ')
~ '}'
})
self.gistseen: self.^name, {
'{'
~ self.sort.head(100).map(*.gist).join(', ')
~ (', ...' if self.elems > 100)
~ '}'
}
}

multi method DUMP(Hash:D: :$indent-step = 4, :%ctx) {
Expand Down
8 changes: 5 additions & 3 deletions src/core/Map.pm6
Expand Up @@ -213,9 +213,11 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
}

multi method gist(Map:D: --> Str:D) {
my @pairs = self.sort.head(100).map: *.gist;
@pairs.push("...") if self.elems > 100;
self.^name ~ '.new((' ~ @pairs.join(', ') ~ '))'
self.^name
~ '.new(('
~ self.sort.head(100).map(*.gist).join(', ')
~ (', ...' if self.elems > 100)
~ '))'
}

multi method perl(Map:D \SELF: --> Str:D) {
Expand Down

0 comments on commit 225d2f9

Please sign in to comment.