Oo for fp

449 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
449
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Oo for fp

  1. 1. (defrecord  CartesianCoordinate  [x  y])
  2. 2. (defrecord  PolarCoordinate  [distance  angle])
  3. 3. (defprotocol  Moveable    (move-­‐north  [self  amount])    (move-­‐east    [self  amount]))
  4. 4. (extend-­‐type  CartesianCoordinate    Moveable    (move-­‐north  [{x  :x  y  :y}  ammount]        (CartesianCoordinate.  (+  x  ammount)  y))    (move-­‐east  [{x  :x  y  :y}  ammount]        (CartesianCoordinate.  x  (+  y  ammount))))
  5. 5. (defrecord  CenterPointRectangle  [center-­‐point  width  height])
  6. 6. (defrecord  CornerPointRectangle  [top-­‐left  bottom-­‐right])
  7. 7. (extend-­‐type  CenterPointRectangle      Moveable    (move-­‐north  [self  ammount]        (update-­‐in  self  [:center-­‐point]                              #(move-­‐x  %  ammount)))    (move-­‐east  [self  ammount]        (update-­‐in  self  [:center-­‐point]                              #(move-­‐y  %  ammount))))

×