Book Image

Clojure Polymorphism

By : Paul Stadig
Book Image

Clojure Polymorphism

By: Paul Stadig

Overview of this book

Clojure is a modern, dynamic language that you can use to develop robust, multithreaded programs. Clojure Polymorphism is a comprehensive guide that shows you how to use Clojure’s features to your advantage. The book begins by describing examples that show how to define and implement abstractions with plain functions and multimethods. Then you'll analyze these examples and separate the good and bad aspects of their design principles. You'll also learn how to perform data transformation abstraction with a plain function and discover how to write new cross-platform predicates while keeping the core of your abstraction free from reader conditionals. The later chapters explain the considerations to keep in mind when implementing Clojure protocols on the Java Virtual Machine (JVM). By the end of this book, you’ll know how to use the various polymorphic tools of Clojure to your advantage while designing your applications.
Table of Contents (7 chapters)

Plain Functions + Client Namespace

A variation on using plain functions would be to return a map that contains the implementation functions:

1 (ns stadig.storage.s3

2   (:refer-clojure :exclude [get])

3   (:require

4    [aws.sdk.s3 :as s3]))

5

6 (defn get

7   [conn bucket key]

8   (s3/get-object conn bucket key))

9

10 (defn put

11   [conn bucket key value]

12   (s3/put-object conn bucket key value))

13

14 (defn delete

15   [conn bucket key]

16   (s3/delete-object conn bucket key))

17

18 (defn close

19   [conn])

20

21 (defn connect

22   [access-key secret-key]

23   (let [conn {:access-key access-key :secret-key secret-key}]

24     {:get (partial get conn)

25      :put (partial put conn)

26      :delete (partial delete conn)

27 ...