{"id":18521792,"url":"https://github.com/simphotonics/list_operators","last_synced_at":"2026-01-07T15:04:28.248Z","repository":{"id":56834026,"uuid":"329946444","full_name":"simphotonics/list_operators","owner":"simphotonics","description":"Extensions providing operators for Dart lists. Package uses null-safety features.","archived":false,"fork":false,"pushed_at":"2024-05-30T17:19:07.000Z","size":242,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T10:11:52.553Z","etag":null,"topics":["dart2","extension","list","operator"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/list_operators","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simphotonics.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-15T15:14:17.000Z","updated_at":"2024-05-30T17:19:11.000Z","dependencies_parsed_at":"2024-05-30T20:07:24.427Z","dependency_job_id":"830c1b52-b2a2-445f-b1cc-5efebd6e5d65","html_url":"https://github.com/simphotonics/list_operators","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/simphotonics/list_operators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Flist_operators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Flist_operators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Flist_operators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Flist_operators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simphotonics","download_url":"https://codeload.github.com/simphotonics/list_operators/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Flist_operators/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28235945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2026-01-07T02:00:05.975Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart2","extension","list","operator"],"created_at":"2024-11-06T17:27:38.320Z","updated_at":"2026-01-07T15:04:28.241Z","avatar_url":"https://github.com/simphotonics.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# List Operators\n[![Dart](https://github.com/simphotonics/list_operators/actions/workflows/dart.yml/badge.svg)](https://github.com/simphotonics/list_operators/actions/workflows/dart.yml)\n\n## Introduction\nThe package [`list_operators`][list_operators] uses Dart Extensions to provide\n*operators* and *utility methods* for objects of type `List` and `Iterable`.\nNote: The operators and methods listed below are *generative* in the sense that they\nreturn a new object. For example the unary negation operator `-a` applied to\na list `a` returns a new list and does not modify the elements of `a` in place.\n\n\nExtensions on `List\u003cT extends num\u003e` make the following\nvector-style operators and methods availabe:\n* subtraction `a-b`: element by element,\n* unary negation `-a`: negates every element,\n* scalar multiplication `a*x`: `x` is a `num`,\n* scalar division `a/x`: `x` is a `num`,\n* integer division `a~/x`: `x` is a `num`,\n* `a.plus(b)`: addition, element by element,\n* `a.innerProd(b)`: the inner product \u0026Sigma;\u003csub\u003ei\u003c/sub\u003e\n  (a\u003csub\u003ei\u003c/sub\u003e \u0026middot;   b\u003csub\u003ei\u003c/sub\u003e),\n* `a.distance(b)`: distance using an Euclidian metric,\n* `a.distanceFromOrigin()`,\n* `a.sphericalToCartesian`: transforms Polar Spherical coordinates to\n   Cartesian coordinates,\n* `a.cartesianToSpherical`: transforms Cartesian coordinates to Polar\n   Spherical coordinates,\n* `a.cartesianToCylindrical`: transforms Cartesian coordinates to Cylindrical\n   coordinates,\n   `a.cylindricalToCartesian`: transforms Cylindrical coordinates to Cartesian\n   coordinates.\n* `a.equal(b)`: Returns `true` if `a[i] == b[i]` for each index `i`,\n* `a.match(b, precision)`: Returns `true` if\n `(a[i] - b[i]) \u003c= precision` for each index `i`.\n  Note: The corresponding matcher is named\n  [`CloseToList`][CloseToList] in analogy with the package [`matcher`][matcher].\n\nFor objects of type `Iterable\u003cT extends num\u003e`, which includes lists and sets,\nthe following methods are provided:\n * `a.abs()`: absolute value,\n * `a.pow()`: power,\n * `a.exp()`: exponentiation,\n * `a.min()`: minimum value,\n * `a.max()`: maximum value,\n * `a.mean()`: mean of all elements,\n * `a.stdDev()`:  standard deviation,\n * `a.sum()`: sum of all elements,\n * `a.prod()`: product of all elements.\n\nFor objects of type `List\u003cT extends Comparable\u003e` the library introduces the\ncomparison operators `a \u003c b, a \u003c= b,  a \u003e b, a \u003e= b`.\n\n\n## Usage\nInclude [`list_operatos`][list_operators] as a `dependency`\nin your `pubspec.yaml` file.\nThe programs below demonstrates how to use operators and\nmethods defined by the library `list_operators`.\n\n#### Methods and Operators For Objects of Type List\\\u003cnum\\\u003e:\n```Dart\nimport 'package:list_operators/list_operators.dart';\n\nvoid main() {\n  final a = [1, 2, 3];\n  final b = [11, 12, 13];\n\n  /// Use with List\u003cnum\u003e\n  print('Absolute value:');\n  print((a - b).abs());\n  print('');\n\n  print('Addition:');\n  print(a.plus(b));\n  print('');\n\n  print('Subtraction:');\n  print(b - a);\n  print('');\n\n  print('Inner product:');\n  print(a.innerProd(b));\n  print('');\n\n  print('Multiplication with a number:');\n  print(a * 10);\n  print('');\n\n  print('Power');\n  print(a.pow(2));\n  print('');\n\n  print('Exponentiation');\n  print(a.exp());\n  print(a.exp(2));\n  print('');\n\n  print('b.distanceFromOrigin()');\n  print(b.distanceFromOrigin);\n  print('');\n\n  print('b.distance(a)');\n  print(b.distance(a));\n  print('');\n\n  /// Dart built-in operator:\n  print('Concatenation:');\n  print(a + b);\n  print('');\n\n  // Creating an unmodifiable list (recursively)\n  print('\\nCreating an unmodifiable list of an object of type List\u003cList\u003cT\u003e\u003e:');\n  final list = [\n    ['one'],\n    ['two'],\n  ];\n\n  // Extension works for objects of type List\u003cT\u003e and List\u003cList\u003cT\u003e\u003e\n  final listUnmodifiable = list.unmodifiable;\n\n  // Prints: List\u003cList\u003cString\u003e\u003e\n  print(listUnmodifiable.runtimeType);\n}\n```\n\u003cdetails\u003e\u003csummary\u003e Click to show console output.\u003c/summary\u003e\n\n```Console\n$ dart numerical_list_example.dart\nAbsolute value:\n[10, 10, 10]\n\nAddition:\n[12, 14, 16]\n\nSubtraction:\n[10, 10, 10]\n\nInner product:\n74\n\nMultiplication with a number:\n[10, 20, 30]\n\nPower\n[1, 4, 9]\n\nExponentiation\n[2.718281828459045, 7.38905609893065, 20.085536923187668]\n[7.38905609893065, 54.598150033144236, 403.4287934927351]\n\nb.distanceFromOrigin()\n20.83266665599966\n\nb.distance(a)\n17.320508075688775\n\nConcatenation:\n[1, 2, 3, 11, 12, 13]\n\nCreating an unmodifiable list of an object of type List\u003cList\u003cT\u003e\u003e:\nList\u003cList\u003cString\u003e\u003e\n```\n\u003c/details\u003e\u003cbr/\u003e\n\n#### Methods For Objects of Type Iterable\\\u003cnum\\\u003e:\n\n```Dart\nimport 'package:list_operators/list_operators.dart';\n\nvoid main() {\n  final b = [11, 12, 13];\n\n  // Operators and method that work with Iterable\u003cnum\u003e\n  print('Minimum: b.min()');\n  print(b.min());\n  print('');\n\n  print('Maximum: b.max()');\n  print(b.max());\n  print('');\n\n  print('Mean: b.mean()');\n  print(b.mean());\n  print('');\n\n  print('Product of all entries: b.prod()');\n  print(b.prod());\n  print('');\n\n  print('Standard deviation: b.stdDev()');\n  print(b.stdDev());prod()\n  print('');\n\n  print('Sum: b.sum()');\n  print(b.sum());\n}\n\n```\n\u003cdetails\u003e\u003csummary\u003e Click to show console output.\u003c/summary\u003e\n\n```Console\n$ dart numerical_iterable_example.dart\nMinimum: b.min()\n11\n\nMaximum: b.max()\n13\n\nMean: b.mean()\n12.0\n\nProduct of all entries: b.prod()\n1716\n\nStandard deviation: b.stdDev()\n1.0\n\nSum: b.sum()\n36\n\n```\n\n\u003c/details\u003e\u003cbr/\u003e\n\n#### Operators For Objects of Type List\\\u003cT extends Comparable\\\u003e:\n\n```Dart\nimport 'package:list_operators/list_operators.dart';\n\nvoid main() {\n  final a = [1, 2, 3];\n  final b = [11, 12, 13];\n\n  // Operators that work with List\u003cT extends Comparable\u003e\n  print('a \u003c b:');\n  print(a \u003c b);\n  print('');\n\n  print('a \u003c= b:');\n  print(a \u003c= b);\n  print('');\n\n  print('a \u003e b:');\n  print(a \u003e b);\n  print('');\n\n  print('b \u003e= b:');\n  print(b \u003e= b);\n  print('');\n\n  final s1 = ['a1', 'a2'];\n  final s2 = ['b1', 'b2'];\n\n  print('s1 \u003c= s2');\n  print(s1 \u003c s2);\n}\n```\n\u003cdetails\u003e\u003csummary\u003e Click to show console output.\u003c/summary\u003e\n\n```Console\n$ dart comparable_list_example.dart\na \u003c b:\ntrue\n\na \u003c= b:\ntrue\n\na \u003e b:\nfalse\n\nb \u003e= b:\ntrue\n\ns1 \u003c= s2\ntrue\n```\n\u003c/details\u003e\u003cbr/\u003e\n\n#### Methods for Exporting Numerical Lists as a String:\n\n```Dart\nimport 'package:list_operators/list_operators.dart';\nvoid main() {\n  final a = [1, 2, 3];\n\n  /// Exporting numerical lists to a `String` object.\n  print('Exporting lists to String:');\n  print(a.export(\n    label: '\u003c\u003cSample label\u003e\u003e',\n    delimiter: ', ',\n    precision: 4,\n  ));\n\n  print('Exporting an object of type List\u003cList\u003cnum\u003e\u003e to String:');\n  print('Each inner list is exported as a row.');\n  print([\n    [1, 2, 3],\n    [101, 102, 103]\n  ].export(label: '\u003c\u003cSample label\u003e\u003e', precision: 6));\n\n  print('Exporting an object of type List\u003cList\u003cnum\u003e\u003e to String.');\n  print('Inner lists are exported as columns.');\n  print([\n    [1, 2, 3],\n    [101, 102, 103]\n  ].export(\n    label: '\u003c\u003cSample label\u003e\u003e',\n    precision: 6,\n    flip: true,\n  ));\n}\n```\n\u003cdetails\u003e\u003csummary\u003e Click to show console output.\u003c/summary\u003e\n\n```Console\n$ dart export_to_string_example.dart\nExporting lists to String:\n\u003c\u003cSample label\u003e\u003e\n1.000,\n2.000,\n3.000,\n\nExporting an object of type List\u003cList\u003cnum\u003e\u003e to String:\nEach inner list is exported as a row.\n\u003c\u003cSample label\u003e\u003e\n1.00000 2.00000 3.00000prod()\n101.000 102.000 103.000\n\nExporting an object of type List\u003cList\u003cnum\u003e\u003e to String.\nInner lists are exported as columns.\n\u003c\u003cSample label\u003e\u003e\n1.00000 101.000\n2.00000 102.000\n3.00000 103.000\n```\n\u003c/details\u003e\n\n\n## Limitations\n\nIn its current version, Dart does not support function\n(and implicitly operator) overloading.\nFor this reason some numerical operations introduced by [`list_operators`][list_operators]\nare not symmetrical, even though intuitively they should be:\n- The expression `[1, 2, 3] * 10` is well defined and the result is `[10, 20, 30]`.\n- The expression `10 * [1, 2, 3]` is not defined since the operator `*`\n  for objects of type `int` expects a second operand of type `num`.\n\nNote: The `+` operator (concatenates two lists) is already\ndefined by Dart's abstract class [`List`][List] and cannot be overridden by an extension on [`List`][List].\nTo add two numerical lists element by element use the method: `List\u003cnum\u003e plus(List\u003cnum\u003e other)`.\n\n## Examples\n\nThe programs shown above are included in the folder [`example`][example].\n\n## Features and bugs\n\nPlease file feature requests and bugs at the [issue tracker][tracker].\n\n[tracker]: https://github.com/simphotonics/list_operators/issues\n\n[CloseToList]: https://pub.dev/documentation/list_operators/latest/list_operators/CloseToList-class.html\n\n[matcher]: https://pub.dev/packages/matcher\n\n[list_operators]: https://pub.dev/packages/list_operators\n\n[List]: https://api.dart.dev/stable/dart-core/List-class.html\n\n[example]: https://github.com/simphotonics/list_operators/tree/main/example\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimphotonics%2Flist_operators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimphotonics%2Flist_operators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimphotonics%2Flist_operators/lists"}