My previous approach to displaying my notes on this site was to render them as a tree of infinitely nested topics and subtopics:
Parents and children
To achieve that nesting, my solution was to manually give each note that represented a subtopic (or subsubsubtopic) a parent value (via markdown frontmatter) and then move any child notes (i.e. notes with a parent value) into their parent’s children array:
Incremental left padding
My solution for visually indicating how those notes related to each other was to multiply each note’s left-padding by 1.4x its descendent level:
Maintaining note hierarchies is a chore
That was a fun programming puzzle to solve, but unfortunately it made my note-taking more difficult by forcing me to decide where each new thought belonged in the hierarchy before I could jot it down.
To remove that friction, I’ve adopted to a flat (and eventually searchable and filterable) approach to note-taking instead. But I wanted to share this former nested-topics solution in case anyone else finds it useful.
I wanted a type-safe pipe utility to help me write Python in a more functional style, but unfortunately toolz.pipe and returns.pipelines.flow both output Any.
Happily, it turns out creating your own pipe mechanism is a one-liner:
Which you can reuse by wrapping it in a function:
And calling it with any number of functions:
So you can stop thinking up names for throwaway variables like these:
While the pipe function above with the Callable[[A], A] type hint works fine if every function in the pipeline outputs the same type (A), the example I showed above doesn’t actually work out very well! Mypy notices that some of the functions (int and float) output a different type than we started with (str), so we aren’t actually passing A all the way through.
After trying a number of workarounds (and getting some good advice on Reddit), I learned that you can either tell Mypy what’s going on by painstakingly articulating every possible overload: