Created
December 24, 2025 22:04
-
-
Save qexat/c7da40ed2f187751aec2e6346740529b to your computer and use it in GitHub Desktop.
functional programmers when they are forced to use python (they are crying and seething)
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
| from __future__ import annotations | |
| from collections.abc import Callable | |
| type List[T] = tuple[()] | tuple[T, List[T]] | |
| def concat_in_reverse[T]( | |
| concatenatee: List[T], | |
| concatenated: List[T], | |
| ) -> List[T]: | |
| match concatenated: | |
| case (): | |
| return concatenatee | |
| case (first, rest): | |
| return concat_in_reverse((first, concatenatee), rest) | |
| def reverse[T](list: List[T]) -> List[T]: | |
| return concat_in_reverse((), list) | |
| def concat[T](left: List[T], right: List[T]) -> List[T]: | |
| return concat_in_reverse(left, reverse(right)) | |
| def map[T, U](func: Callable[[T], U], list: List[T]) -> List[U]: | |
| match list: | |
| case (): | |
| return () | |
| case (first, rest): | |
| return (func(first), map(func, rest)) | |
| def fold[T, Acc]( | |
| func: Callable[[Acc, T], Acc], | |
| init: Acc, | |
| list: List[T], | |
| ) -> Acc: | |
| match list: | |
| case (): | |
| return init | |
| case (first, rest): | |
| return fold(func, func(init, first), rest) | |
| def join[T](list: List[List[T]]) -> List[T]: | |
| return fold(concat, (), list) | |
| def bind[T, U](list: List[T], func: Callable[[T], List[U]]) -> List[U]: | |
| return join(map(func, list)) |
aight time to hop out of nvim. but let's hop on some linkedin instead tho ๐๐ผ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please never cook again lil bro ๐