This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final selector = Selector(); | |
selector | |
.when((value) => value == 3).then((value) => value * 2) | |
.whenIsEqual((value) => value == 'QQQ').then((value) { print(value); return null; }) | |
.fallback((value) => { 'x': 42 }); | |
final selector2 = Selector<int, int>(); | |
selector2 | |
.when((value) => value == 3).then((value) => value * 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Selector = { | |
}; | |
interface CaseLine<T, G> { | |
condition(value: T): boolean; | |
body(value: T): void | G; | |
} | |
interface Switcher<T, G> { | |
case(caseLine: CaseLine<T, G>): this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const binarySearch = ( | |
array: number[], | |
element: number, | |
range: [left: number, right: number] = [0, array.length - 1], | |
): number => { | |
let left = range[0]; | |
let right = range[1]; | |
let halfIndex = -1; | |
while (left < right) { |
OlderNewer