Why does TypeScript infer the ‘never’ type when reducing an Array with concat?

I believe this is because the type for [] is inferred to be never[], which is the type for an array that MUST be empty. You can use a type cast to address this: [‘a’, ‘b’, ‘c’].reduce((accumulator, value) => accumulator.concat(value), [] as string[]); Normally this wouldn’t be much of a problem since TypeScript does a … Read more

Functional pipes in python like %>% from R’s magrittr

Pipes are a new feature in Pandas 0.16.2. Example: import pandas as pd from sklearn.datasets import load_iris x = load_iris() x = pd.DataFrame(x.data, columns=x.feature_names) def remove_units(df): df.columns = pd.Index(map(lambda x: x.replace(” (cm)”, “”), df.columns)) return df def length_times_width(df): df[‘sepal length*width’] = df[‘sepal length’] * df[‘sepal width’] df[‘petal length*width’] = df[‘petal length’] * df[‘petal width’] x.pipe(remove_units).pipe(length_times_width) … Read more

How to compare two functions for extensional equivalence, as in (λx.2*x) == (λx.x+x)?

It’s pretty well-known that general function equality is undecidable in general, so you’ll have to pick a subset of the problem that you’re interested in. You might consider some of these partial solutions: Presburger arithmetic is a decidable fragment of first-order logic + arithmetic. The universe package offers function equality tests for total functions with … Read more