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 layered-example.data.mysql-cargo-repository | |
(:refer-clojure :exclude [find]) | |
(:require [layered-example.domain.cargo.cargo-repository :refer [CargoRepository -find -add! -update!]] | |
[layered-example.domain.cargo.cargo :refer [map->Cargo set-cargo-id]] | |
[clojure.set :refer [rename-keys]] | |
[clojure.java.jdbc :as db])) | |
(defn row->cargo [row] | |
(-> row | |
(select-keys [:id :size :voyage_id]) |
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 layered-example.domain.cargo.cargo-repository | |
(:refer-clojure :exclude [find])) | |
(def find nil) | |
(def add! nil) | |
(def update! nil) | |
(defprotocol CargoRepository | |
(-find [this cargo-id]) | |
(-add! [this a-cargo]) |
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 layered-example.domain.cargo.cargo) | |
(defrecord Cargo [cargo-id size voyage-id]) | |
(defn create-new-cargo [& {:keys [size voyage-id] :as cargo-data}] | |
{:pre [(integer? size) | |
(nil? voyage-id)]} | |
(map->Cargo cargo-data)) | |
(defn book-onto-voyage [a-cargo & {:keys [voyage-id]}] |
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
autocmd FileType clojure nnoremap <buffer> <F5> :Require!<CR>:RunTests<CR> | |
0 autocmd FileType clojure nnoremap <buffer> <F6> :Require!<CR>:.RunTests<CR> |
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
module Vector = | |
type private PolarVector = { | |
r: double; | |
a: double; | |
} | |
type private RectangularVector = { | |
x: double; | |
y: double; | |
} |
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
module Vector = | |
type PolarVector = { | |
r: double; | |
a: double; | |
} | |
type RectangularVector = { | |
x: double; | |
y: double; | |
} |
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 Vector(rep) { | |
switch (rep) { | |
case Vector.representations.Polar: | |
this.vector = { rep: rep, r: arguments[1], a: arguments[2] } | |
break; | |
case Vector.representations.Rectangular: | |
this.vector = { rep: rep, x: arguments[1], y: arguments[2] } | |
break; | |
default: | |
throw Error("Unknown representation " + rep) |
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 Vector(x, y) { | |
this.x = x; | |
this.y = y; | |
this.Add = function(addend) { | |
if(!(addend instanceof Vector)) { | |
throw Error("addend not a Vector") | |
} | |
return new Vector(this.x + addend.x, this.y+addend.y) | |
} |
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
var v1 = new VectorMagnitudeAngle(10, Math.PI/4) | |
var v2 = new Vector(-10/Math.sqrt(2), 10/Math.sqrt(2)) | |
var v3 = v1.Add(v2); | |
console.log(v3.X()+ ", " +v3.Y()) | |
//outputs: 8.659560562354932e-16, 14.14213562373095 |
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 VectorMagnitudeAngle(r, theta) { | |
this.X = function() { | |
return r * Math.cos(theta) | |
} | |
this.Y = function() { | |
return r * Math.sin(theta) | |
} | |
this.Add = function(addend) { |