blob: 4b6ef03d35a96e8848609f4d2ccc8603b198405b [file] [log] [blame]
/*
* Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
/**
* @assertion an extension declaration is a top-level declaration with a grammar
* similar to:
* <extension> ::=
* `extension' <identifier>? <typeParameters>? `on' <type> `?'? `{'
* memberDeclaration*
* `}'
* Such a declaration introduces its name (the identifier) into the surrounding
* scope. The name does not denote a type, but it can be used to denote the
* extension itself in various places. The name can be hidden or shown in import
* or export declarations.
*
* @description Check that the name does not denote a type
* @compile-error
* @author sgrekhov@unipro.ru
*/
// SharedOptions=--enable-experiment=extension-methods
extension MyFancyList<T> on List<T> {
int get doubleLength => this.length * 2;
List<T> operator-() => this.reversed.toList();
List<List<T>> split(int at) => <List<T>>[this.sublist(0, at), this.sublist(at)];
static String get className => "List";
}
main() {
MyFancyList<String> list = ["Lily", "was", "here"];
}