Skip to content

Instantly share code, notes, and snippets.

@LeeeeT
LeeeeT / pythags.py
Last active August 30, 2024 17:37
Finding pythagorean triples ("I hate my life" edition)
from sys import setrecursionlimit
setrecursionlimit(10000)
lift2 = lambda identity: lambda apply: lambda function: lambda first: apply(apply(identity(function))(first))
bind = lambda map: lambda join: lambda value: lambda function: join(map(function)(value))

Keybase proof

I hereby claim:

  • I am leeeet on github.
  • I am leeeet (https://keybase.io/leeeet) on keybase.
  • I have a public key ASDYtFndK00PVisAWXuWqSJ5PFdRdEhVGog6z-RPDfQ15wo

To claim this, I am signing this object:

@LeeeeT
LeeeeT / scott.py
Created May 28, 2024 19:20
Scott encoding maxed out
from __future__ import annotations
import builtins
from typing import Protocol
class Ty[T]:
pass
@LeeeeT
LeeeeT / sort.py
Last active April 28, 2024 09:56
from collections.abc import Callable
from dataclasses import dataclass
from typing import Protocol, Self
def curry[First, *Rest, Result](
function: Callable[[First, *Rest], Result],
) -> Callable[[*Rest], Callable[[First], Result]]:
return lambda *rest: lambda first: function(first, *rest)
@LeeeeT
LeeeeT / async_option.py
Last active April 8, 2024 18:37
Async-Option monad composition revised
import asyncio
from collections.abc import Callable, Coroutine
from dataclasses import dataclass
from typing import Any
def curry[First, *Rest, Result](function: Callable[[First, *Rest], Result]) -> Callable[[*Rest], Callable[[First], Result]]:
return lambda *rest: lambda first: function(first, *rest)
@LeeeeT
LeeeeT / io.py
Last active March 2, 2024 22:12
Pure IO (does work)
import sys
from collections.abc import Callable, Iterator
from functools import cache
type Lazy[T] = Callable[[], T]
type Stream[T] = Lazy[tuple[T, Stream[T]]]
@LeeeeT
LeeeeT / io.py
Created February 25, 2024 12:34
Pure IO
import sys
from collections.abc import Callable, Iterator
from functools import cache
type Lazy[T] = Callable[[], T]
def run_lazy[T](lazy: Lazy[T]) -> T:
@LeeeeT
LeeeeT / lazy.py
Created February 24, 2024 11:43
Laziness complete
from __future__ import annotations
from collections.abc import Callable, Iterator
from typing import Protocol, cast
type Lazy[Value] = Callable[[], Value]
def lazify[Value](value: Value) -> Lazy[Value]:
@LeeeeT
LeeeeT / lazy.py
Created February 8, 2024 01:26
Lazy monad
from collections.abc import Callable
from dataclasses import dataclass
from typing import Concatenate, Final
@dataclass(frozen=True)
class Partial1[First, **P, Result]:
function: Callable[Concatenate[First, P], Result]
first: First
@LeeeeT
LeeeeT / awaitable_option.py
Last active February 7, 2024 22:46
Awaitable-Option monad composition
from asyncio import run
from collections.abc import Coroutine
from dataclasses import dataclass
from typing import Any, Protocol
class Callable[*Arguments, Result](Protocol):
def __call__(self, *args: *Arguments) -> Result:
...