grantnicholas.io
A blog about my adventures in programming
![](/assets/images/github.png)
The M-word
Monads can be confusing but they shouldn't be. Monads from an OOP perspective are simply an interface with two methods. That is it. Here is a working python example of two separate Monads, one for a list and one for an option type. """ interface Monad def return(val:T):M[T] def bind(val:M[T],...
Profiling-your-code-part-1
I'm going to run through a simple example in order to demonstrate how to profile and optimize code without worrying about other complicated stuff happening. Let's say we are doing some machine learning algorithm that needs to find the distance between two vectors many, many times. This can happen often,...
Profiling-and-optimizing-your-code
So python is really slow. Benchmarks are notoriously hard to do correctly so I'm not going to cite any specific benchmarks but being a non-compiled unityped scripting language just makes python slow. So why use python if it is so slow? Because speed of execution of this app is non...
Named tuple python trick
What happens when we need to glue small pieces of data together in order to return them from a function, pass them into a function, or just logically keep them together. In python people usually return tuples of values from functions like below. #arguments -> (max,min) of arguments def getmaxmin(a,b,c):...