| | Object-Oriented | Functional |
|----- | ----- | |
| Statically-typed | Java
C#
C++ | OCaml
Haskell
Scala |
| Dynamically-typed | Ruby Python | JavaScript Clojure Erlang Elixir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns foo.me | |
(:require [clojure.test :refer [deftest is are run-tests]])) | |
(defn me [x] | |
(+ x 2)) | |
(deftest test-me | |
(is (= 4 (me 2)))) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my.test | |
(:require [cljs.math :as m] | |
[clojure.test.check :as tc] | |
[clojure.test.check.generators :as gen] | |
[clojure.test.check.properties :as prop :include-macros true])) | |
(defn d= [a b] (or (= a b) (and (js/isNaN a) (js/isNaN b)))) | |
(def safe-integer (gen/choose js/Number.MIN_SAFE_INTEGER js/Number.MAX_SAFE_INTEGER)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://guides.rubyonrails.org/association_basics.html | |
(def book-info {:title "Seven Habits of Highly Effective People"}) | |
(def author {:name "Stephen Covey" | |
:id "steph"}) | |
(def association {:association-field :author-id | |
:parent-field :id}) | |
(defn add-to [parent child association] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "object", | |
"required": ["firstName", "lastName"], | |
"properties": { | |
"firstName": {"type": "string"}, | |
"lastName": {"type": "string"}, | |
"bookList": {"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
"math/big" | |
) | |
func factorial(x *big.Int) *big.Int { | |
n := big.NewInt(1) | |
if x.Cmp(big.NewInt(0)) == 0 { | |
return n | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Godel Escher Bach - G fractal from Chapter 5 | |
(set! | |
(.-innerHTML js/klipse-container) | |
"<canvas style='width:100%; height:100%'></canvas>") | |
(def canvas (aget (js/document.getElementsByTagName "canvas") 0)) | |
(set! (.-height canvas) (.-innerHeight js/window)) | |
(def ctx (.getContext canvas "2d")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function joinArrays(a, b, keyA, keyB) { | |
var mapA = _.keyBy(a, keyA); | |
var mapB = _.keyBy(b, keyB); | |
var mapsMerged = _.merge(mapA, mapB); | |
return _.values(mapsMerged); | |
} | |
var dbBookInfos = [ | |
{ | |
"isbn": "978-1982137274", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy | |
(defn proxy [m] | |
(js/Proxy. m #js {:get (fn [target prop] | |
(let [prop' (if (vector? target) | |
(js/parseInt prop) | |
(keyword prop))] | |
(let [v (or (get target prop') | |
(get target prop))] | |
(if (coll? v) | |
(proxy v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setVerbatim (obj, k, v) { | |
// In Lodash, a dot in a key is interpreted as a nesting object | |
// For instance, _.set({}, "a.b", 2) returns {"a": {"b": 2}} | |
// While setVerbatim({}, "a.b", 2) returns {"a.b": 2} | |
return _.merge(obj, {[k]: v}) | |
} | |
function flattenObject(obj, prefix = '') { | |
return _.reduce(obj, | |
function(acc, v, k) { |
NewerOlder