Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Unified Diff: sdk/lib/convert/converter.dart

Issue 19000006: First version of Codecs and Converters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert sdk/lib/json change. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/convert/converter.dart
diff --git a/sdk/lib/convert/converter.dart b/sdk/lib/convert/converter.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8624ab7ed93e3e6e56bf247d7a767d45eb9cb6d1
--- /dev/null
+++ b/sdk/lib/convert/converter.dart
@@ -0,0 +1,40 @@
+// Copyright (c) 2013, 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.
+
+part of dart.convert;
+
+/**
+ * A [Converter] converts data from one representation into another.
+ *
+ * *Converters are still experimental and are subject to change without notice.*
+ *
+ */
+abstract class Converter<S, T> {
+ /**
+ * Converts [input] and returns the result of the conversion.
+ */
+ T convert(S input);
+
+ /**
+ * Fuses `this` with [other].
+ *
+ * Encoding with the resulting converter is equivalent to converting with
+ * `this` before converting with `other`.
+ */
+ Converter<S, dynamic> fuse(Converter<T, dynamic> other) {
+ return new _FusedConverter<S, T, dynamic>(this, other);
+ }
+}
+
+
+class _FusedConverter<S, M, T> extends Converter<S, T> {
Lasse Reichstein Nielsen 2013/07/12 11:50:47 Comment for class. I assume this is just the naïve
floitsch 2013/07/12 16:09:15 Done.
+ final Converter _first;
+ final Converter _second;
+
+ _FusedConverter(Converter<S, M> first, Converter<M, T> second)
Lasse Reichstein Nielsen 2013/07/12 11:50:47 this._first, this._second
floitsch 2013/07/12 16:09:15 Done.
+ : this._first = first,
+ this._second = second;
+
+ T convert(S input) => _second.convert(_first.convert(input));
+}

Powered by Google App Engine
This is Rietveld 408576698