Skip to content

Instantly share code, notes, and snippets.

View noullet's full-sized avatar
💪

Nicolas Noullet noullet

💪
View GitHub Profile
@noullet
noullet / typed-fp-function-overhead.md
Last active October 25, 2017 12:17
Typed FP and function cognitive overhead

Here is an elaboration for three properties which I think enable replacing flat code by functions without adding cognitive overhead for the person who reads the code:

Expressive type signatures

  • Benefits: if type signatures convey a lot of meaning and if such signatures can be trusted, then they may be sufficient. In some cases, you may not need to know more about a function than the fact that it safely converts a value from type A to type B.
  • Tooling opportunities: an editor can show type signatures at hand, e.g. on hover or even by inlining them.
  • Without it: if the function signature is Int -> Void or even Int -> Int, you must look at its definition to know what it does.

Absence of side effects

  • Benefits: the only "effect" of functions is what they return. Just by looking at what happens to the return value of a function in the calling code thus allows knowing all the consequences of the function call.
  • Tooling opportunities: referential transparency allows replacin
@noullet
noullet / C.java
Last active August 29, 2015 14:08
applyOptional in Java to simulate liftA3
public class C {
private String t;
private Integer u;
private String v;
public C(String t, Integer u, String v) {
this.t = t;
this.u = u;
this.v = v;