Histomorphisms, Zygomorphisms and Futumorphisms specialised to lists

Zygomorphism is the high-falutin’ mathsy name we give to folds built from two semi-mutually recursive functions. I’ll give an example. Imagine a function pm :: [Int] -> Int (for plus-minus) which intersperses + and – alternately through a list of numbers, such that pm [v,w,x,y,z] = v – (w + (x – (y + z))). … Read more

Recursively Get Properties & Child Properties Of A Class

You have two problems with your code: because of condition if (property.PropertyType.Assembly == objType.Assembly) you will omit System.Collections like List<> you do not treat differently propValue that are collections. Hence it will print List properties, not its elements properties. You can change that for example into: public void PrintProperties(object obj, int indent) { if (obj … Read more

How to implement TypeScript deep partial mapped type not breaking array properties

With TS 2.8 and conditional types we can simply write: type DeepPartial<T> = { [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]> }; or with [] instead of Array<> that would be: type DeepPartial<T> = { [P in keyof T]?: T[P] extends (infer U)[] … Read more

javascript: recursive anonymous function?

You can give the function a name, even when you’re creating the function as a value and not a “function declaration” statement. In other words: (function foo() { foo(); })(); is a stack-blowing recursive function. Now, that said, you probably don’t may not want to do this in general because there are some weird problems … Read more

What is the maximum recursion depth, and how to increase it?

It is a guard against a stack overflow, yes. Python (or rather, the CPython implementation) doesn’t optimize tail recursion, and unbridled recursion causes stack overflows. You can check the recursion limit with sys.getrecursionlimit: import sys print(sys.getrecursionlimit()) and change the recursion limit with sys.setrecursionlimit: sys.setrecursionlimit(1500) but doing so is dangerous — the standard limit is a … Read more