Skip to content

Instantly share code, notes, and snippets.

View 3AHAT0P's full-sized avatar
:octocat:

3@H@T0P 3AHAT0P

:octocat:
View GitHub Profile
@3AHAT0P
3AHAT0P / Selector.dart
Created December 11, 2021 19:02
Selector pattern on the dart
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)
@3AHAT0P
3AHAT0P / insane_fp_switch.ts
Created June 24, 2022 20:25
Insane FP Switch
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;
@3AHAT0P
3AHAT0P / sort_by_copy.ts
Last active April 5, 2023 12:45
Implementation custom sorting algorithm (sorting by copying to new array)
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) {