Panda Generics
Panda Generics brings generics, also known as multi-methods, to JavaScript. Generics are great for functional programming because they offer multi-argument dispatch. That is, you aren't limited to an implicit first argument as you are with object-oriented methods.
Installation
npm i panda-generics
Usage
import Generics from "panda-generics"import isObject from "panda-parchment" equal = Genericscreate name: "equal" description: "'Deep' equality operator" : a == b # fallback to shallow equality # when comparing objects, recursively check the values # corresponding to the union of their properties— # return false on the first inequality Genericsdefine equalisObjectisObject a == b || do -> keys = Objectkeys a...Objectkeys b... for key from keys if ! equal akeybkey return false true # when comparing arrays, recursively check values # after making sure they're the same length # return false on the first inequality Genericsdefine equalisArrayisArray ax == bx || do -> return false if axlength != bxlength for i in 0..axlength if !equal axibxi return false true equal "this""this" # => true, shallow equality works here equal x: 1y: 2 x: 1y: 2 # => true, deep equality equal 1..51..5# true, deep equality equal x: 1y: 21..5# false