flurine_lambda 0.9.3+1 flurine_lambda: ^0.9.3+1 copied to clipboard
A starting point for Dart libraries or applications.
A library to generate simple formula and get values from it in iterative manner.
Usage #
A simple usage example:
import 'package:lambda/flurine_lambda.dart';
const TIME = 'tm';
const CONCAT = 'cc';
void main() async {
Handler.registerMany({
CONST: () => ConstHandler(),
TIME: () => TimeHandler(),
CONCAT: () => ConcatHandler(),
});
await Vein.init();
final lambda = Lambda.parse('\$cc("Hello : ",tm(2))\$');
await lambda.execute();
lambda.vein.listen(onData);
}
void onData(data) {
print(data);
}
In above formula : #
- 'tm','cc' is Lambda keyword,
- 2 (integer),"Hello : " (String) are arguments which are handled by TimeHandler,ConcatHandler.
- whole lambda should be wrapped between $ sign.
- handlers should be registerd first.
Here whole data is processed behind single Isolate (here [Vein]) which should be initialized first.
Break Down : #
- Here 'tm(2)' will generate values repeatively as defined in TimeHandler ( Every 2 seconds).
- Output of 'tm(2)' will appended to "Hello : " (first parameter) as defined in ConcatHandler.
So, this will print values every two seconds ...
Hello : 12
Hello : 14
Hello : 16
Hello : 18
.
.
.
I don't know where you can use this library or an idea like this but here it is.
class TimeHandler extends Handler {
@override
Future compute() async {
return DateTime.now().second;
}
@override
Duration get repeatingDuration => Duration(seconds:params.last);
}
class CounterHandler extends Handler {
@override
Duration get repeatingDuration => null;
int begin, end, step,current;
@override
set params(List params) {
this.params = params;
begin = params[0];
end = params[1];
step = params[2];
current = params[3];
}
@override
Future compute() async {
if (current == null || current > end) current = begin;
int temp = current;
current = current + step;
return temp;
}
}
class ConcatHandler extends Handler{
@override
Duration get repeatingDuration => null;
@override
Future compute() async{
return params.join();
}
}