Skip to content

Commit

Permalink
Fix deepmap returning a Seq instead of the desired Listy type
Browse files Browse the repository at this point in the history
If the object's type is List or a subclass of List, use the object's
type for the result, so deepmap(op, (1, 2, [3, 4])) will return (op(1),
op(2), [op(3), op(4)]). In other cases (like Seq or Range) use List.
  • Loading branch information
niner committed Aug 24, 2015
1 parent f8692f1 commit 65a02f4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/metaops.pm
Expand Up @@ -555,7 +555,10 @@ multi sub deepmap(\op, \obj) {
}
}.new(op, iterable.iterator);

nqp::iscont(obj) ?? List.from-iterator(result).eager.item !! List.from-iterator(result).eager
my $type = nqp::istype(obj, List) ?? obj.WHAT !! List; # keep subtypes of List
my \retval = $type.from-iterator(result);
retval.is-lazy(); # fully reifies as a side-effect
nqp::iscont(obj) ?? retval.item !! retval;
}

multi sub deepmap(\op, Associative \h) {
Expand Down

0 comments on commit 65a02f4

Please sign in to comment.