Skip to content

Instantly share code, notes, and snippets.

@escamoteur
Created November 9, 2025 15:24
Show Gist options
  • Select an option

  • Save escamoteur/e92fc4b2a0aaf4d180f46110543c6706 to your computer and use it in GitHub Desktop.

Select an option

Save escamoteur/e92fc4b2a0aaf4d180f46110543c6706 to your computer and use it in GitHub Desktop.
// ignore_for_file: unused_local_variable, unused_field
class MyCallable<TParam, TReturn> {
final TReturn _defaultValue;
MyCallable(this._defaultValue);
TReturn call([TParam? value]) {
if (value != null) {
print('MyCallable instance called with parameter: $value');
} else {
print('MyCallable instance called without parameter');
}
return _defaultValue;
}
}
class Processor<R1, R2> {
final R1 Function()? _callbackWithoutParam;
final void Function() voidCallback;
final void Function()? nullableCallBack;
final void Function()? nullableCallBack2;
Processor({
R1 Function()? callbackWithoutParam,
this.nullableCallBack,
this.nullableCallBack2,
required this.voidCallback
}) : _callbackWithoutParam = callbackWithoutParam;
}
void main() {
var callable = MyCallable<String, String>('Default string result');
var callableNoParamVoid = MyCallable<void, void>('Default string result');
bool isActive=true;
final handler = isActive ? callableNoParamVoid : null;
Processor<String, bool>(
callbackWithoutParam: callable,
voidCallback: callable,
nullableCallBack: callableNoParamVoid,
nullableCallBack2: handler
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment