Skip to content

Commit

Permalink
Merge pull request #112 from kodjodevf/master
Browse files Browse the repository at this point in the history
Implement some methods in List and Iterable
  • Loading branch information
ethanblake4 authored Oct 7, 2023
2 parents 0dcd3dd + 23289e5 commit da40f5f
Show file tree
Hide file tree
Showing 2 changed files with 439 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/src/eval/shared/stdlib/core/iterable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class $Iterable<E> implements Iterable<E>, $Instance {
BridgeParameter('toElement', BridgeTypeAnnotation(BridgeTypeRef.type(RuntimeTypes.functionType)), false),
], returns: BridgeTypeAnnotation(BridgeTypeRef(BridgeTypeSpec('dart:core', 'Iterable')))),
isStatic: false),
'toList': BridgeMethodDef(
BridgeFunctionDef(
params: [
BridgeParameter('growable', BridgeTypeAnnotation(BridgeTypeRef.type(RuntimeTypes.boolType)), true),
],
returns: BridgeTypeAnnotation(
BridgeTypeRef(CoreTypes.list, [BridgeTypeRef.type(RuntimeTypes.dynamicType)]))),
isStatic: false),
},
getters: {
'iterator': BridgeMethodDef(
Expand Down Expand Up @@ -51,6 +59,8 @@ class $Iterable<E> implements Iterable<E>, $Instance {
return $Function(__map);
case 'iterator':
return $Iterator.wrap($value.iterator);
case 'toList':
return __toList;
default:
return _superclass.$getProperty(runtime, identifier);
}
Expand All @@ -75,6 +85,12 @@ class $Iterable<E> implements Iterable<E>, $Instance {
return $Iterable.wrap((target!.$value as Iterable).map((e) => toElement.call(runtime, null, [e])!.$value));
}

static const $Function __toList = $Function(_toList);

static $Value? _toList(Runtime runtime, $Value? target, List<$Value?> args) {
return $List.wrap((target!.$value as Iterable).toList(growable: args[0]?.$value ?? true));
}

@override
bool any(bool Function(E element) test) => $value.any(test);

Expand Down
Loading

0 comments on commit da40f5f

Please sign in to comment.