Skip to content

Commit

Permalink
extract
Browse files Browse the repository at this point in the history
  • Loading branch information
danylo-safonov-solid committed Nov 16, 2023
1 parent 9e2678b commit 7dbe272
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 11 additions & 0 deletions lib/src/add_imports/better_map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This is an internal implementation so it is okay here.
// ignore_for_file: public_member_api_docs
typedef Predicate<T> = bool Function(T);

extension BetterMap<K, V> on Map<K, V> {
Map<K, V1> mapValues<V1>(V1 Function(V) f) =>
map((k, v) => MapEntry(k, f(v)));

MapEntry<K, V> firstWhereValue(Predicate<V> predicate) =>
entries.firstWhere((e) => predicate(e.value));
}
12 changes: 3 additions & 9 deletions lib/src/add_imports/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// ignore_for_file: public_member_api_docs

import 'package:collection/collection.dart';
import 'package:deno_postgres_interop/src/add_imports/better_map.dart';
import 'package:deno_postgres_interop/src/add_imports/class_interop_data.dart';
import 'package:yaml/yaml.dart';

Expand Down Expand Up @@ -33,10 +34,8 @@ class Config {
}
}

String _filenameForClass(String classname) => classesMap.entries
.firstWhere(
(e) => e.value.any((interop) => interop.jsName == classname),
)
String _filenameForClass(String classname) => classesMap
.firstWhereValue((v) => v.map((e) => e.jsName).contains(classname))
.key;

String importStringForClass(String classname) {
Expand All @@ -46,8 +45,3 @@ class Config {
return 'import { $classname } from "$url";';
}
}

extension MapMapValues<K, V> on Map<K, V> {
Map<K, V1> mapValues<V1>(V1 Function(V) f) =>
map((k, v) => MapEntry(k, f(v)));
}

0 comments on commit 7dbe272

Please sign in to comment.