Skip to content

Instantly share code, notes, and snippets.

View jfmengels's full-sized avatar

Jeroen Engels jfmengels

View GitHub Profile
@jfmengels
jfmengels / problem.md
Last active April 12, 2020 16:10
API design puzzle - The car factory

Imagine you try to design "factories". You have factories that can build Diesel cars, and factories that can build any kind of car (Diesel and Gas, but other kinds of cars could exist). Let's say you want the user to be able to create their customized car factory, for which you provide an API, like

I have a module Factory which defines a Factory and a Car type, all opaque. I provide two functions createCarFactory and createDieselCarFactory, where the first one takes a use-provided function that can return a list of any cars (and they can be mixed), and the second one can only generate Diesel cars.

I want the garantee as the module author, that users won't be able to provide functions that create cars other than diesel cars in the createDieselCarFactory, while still allowing to create any kind of car with the createCarFactory function.

I want the type system to be the one to complain if these guarantees are not respected by the user.

@jfmengels
jfmengels / NoMissingVariants.elm
Last active June 11, 2020 14:55
NoMissingVariants rule
module NoMissingVariants exposing (rule)
import Dict exposing (Dict)
import Elm.Syntax.Declaration as Declaration exposing (Declaration)
import Elm.Syntax.Expression as Expression exposing (Expression)
import Elm.Syntax.Node as Node exposing (Node)
import Elm.Syntax.Type exposing (Type)
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation)
import Review.Rule as Rule exposing (Error, Rule)
import Set exposing (Set)
removeRange : Node TypeAnnotation -> Node TypeAnnotation
removeRange (Node _ value) =
Node Range.emptyRange
(case value of
TypeAnnotation.FunctionTypeAnnotation input output ->
TypeAnnotation.FunctionTypeAnnotation (removeRange input) (removeRange output)
TypeAnnotation.Typed (Node _ nameNode) params ->
TypeAnnotation.Typed (Node Range.emptyRange nameNode) (List.map removeRange params)
module NoMissingTypeConstructor exposing (rule)
import Dict exposing (Dict)
import Elm.Syntax.Declaration as Declaration exposing (Declaration)
import Elm.Syntax.Expression as Expression exposing (Expression)
import Elm.Syntax.Node as Node exposing (Node)
import Elm.Syntax.Type exposing (Type)
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation)
import Review.Rule as Rule exposing (Error, Rule)
import Set exposing (Set)
@jfmengels
jfmengels / NoMissingTypeConstructor.elm
Last active September 27, 2021 17:55
NoMissingTypeConstructor elm-review rule
module NoMissingTypeConstructor exposing (rule)
import Dict exposing (Dict)
import Elm.Syntax.Declaration as Declaration exposing (Declaration)
import Elm.Syntax.Expression as Expression exposing (Expression)
import Elm.Syntax.ModuleName exposing (ModuleName)
import Elm.Syntax.Node as Node exposing (Node)
import Elm.Syntax.Type exposing (Type)
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation)
import Review.ModuleNameLookupTable as ModuleNameLookupTable exposing (ModuleNameLookupTable)
@jfmengels
jfmengels / a.js
Last active January 24, 2022 21:11
TRMC in Elm
/* Corresponds to the following Elm code
map fn list =
case list of
[] -> []
x :: xs ->
fn x :: map fn xs
*/
@jfmengels
jfmengels / Differences between elm-review.md
Last active July 19, 2024 09:45
elm-review vs ESLint
@jfmengels
jfmengels / lodash-fp-documentation.md
Last active July 25, 2024 05:02
Generated docs for Lodash/fp. Help make them better at https://github.com/jfmengels/lodash-fp-docs
@jfmengels
jfmengels / Rope emptiness.txt
Created July 27, 2024 20:03
Rope emptiness
This file has been truncated, but you can view the full file.
rope: Branch [Leaf [],Branch [Leaf [],Leaf [],Branch [Leaf [],Branch [Leaf [],Branch [Branch [Leaf [],Leaf [],Leaf []],Branch [Branch [Branch [Branch [Leaf [],Branch [Leaf [],Leaf [],Leaf []]],Branch [Leaf [],Leaf [],Leaf []]],Branch [Leaf [],Leaf [],Leaf []]],Branch [Leaf [],Leaf [],Leaf []]]],Leaf []]]],Leaf [],Branch [Leaf [],Leaf []],Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Leaf [],Branch [Leaf [],Leaf [],Leaf [],Branch [Leaf [],Branch [Leaf [],Branch [Branch [Leaf [],Leaf [],Leaf []],Leaf []],Leaf []]],Leaf []]],Branch [Leaf [],Leaf [],Leaf [],Leaf [],Leaf []]],Branch [Leaf [],Leaf [],Leaf [],Branch [Leaf [],Branch [Leaf [],Branch [Branch [Leaf [],Leaf [],Leaf []],Leaf []],Leaf []]],Leaf []]],Branch [Leaf [],Leaf [],Branch [Leaf [],Leaf []],Branch [Leaf [],Branch [Leaf [],Branch [Branch [Leaf [],Leaf [],Leaf []],Leaf []],Leaf []]],Leaf []]],Branch [Leaf [],Leaf []