blob: 6dd189a9ff23d4e14b972392b530bad2aab981ae [file] [log] [blame]
// Copyright (c) 2018, 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.
Object id(Object obj) => obj;
class Either2<T1, T2> {
final int _which;
final T1 _t1;
final T2 _t2;
Either2.t1(this._t1)
: _t2 = null,
_which = 1;
Either2.t2(this._t2)
: _t1 = null,
_which = 2;
T map<T>(T Function(T1) f1, T Function(T2) f2) {
return _which == 1 ? f1(_t1) : f2(_t2);
}
Object toJson() => map(id, id);
}
class Either3<T1, T2, T3> {
final int _which;
final T1 _t1;
final T2 _t2;
final T3 _t3;
Either3.t1(this._t1)
: _t2 = null,
_t3 = null,
_which = 1;
Either3.t2(this._t2)
: _t1 = null,
_t3 = null,
_which = 2;
Either3.t3(this._t3)
: _t1 = null,
_t2 = null,
_which = 3;
T map<T>(T Function(T1) f1, T Function(T2) f2, T Function(T3) f3) {
switch (_which) {
case 1:
return f1(_t1);
case 2:
return f2(_t2);
case 3:
return f3(_t3);
default:
throw 'Invalid state.';
}
}
Object toJson() => map(id, id, id);
}
class Either4<T1, T2, T3, T4> {
final int _which;
final T1 _t1;
final T2 _t2;
final T3 _t3;
final T4 _t4;
Either4.t1(this._t1)
: _t2 = null,
_t3 = null,
_t4 = null,
_which = 1;
Either4.t2(this._t2)
: _t1 = null,
_t3 = null,
_t4 = null,
_which = 2;
Either4.t3(this._t3)
: _t1 = null,
_t2 = null,
_t4 = null,
_which = 3;
Either4.t4(this._t4)
: _t1 = null,
_t2 = null,
_t3 = null,
_which = 4;
T map<T>(T Function(T1) f1, T Function(T2) f2, T Function(T3) f3,
T Function(T4) f4) {
switch (_which) {
case 1:
return f1(_t1);
case 2:
return f2(_t2);
case 3:
return f3(_t3);
case 4:
return f4(_t4);
default:
throw 'Invalid state.';
}
}
Object toJson() => map(id, id, id, id);
}
class FileOperation {}