Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Clojure Polymorphism
  • Table Of Contents Toc
Clojure Polymorphism

Clojure Polymorphism

By : Paul Stadig
close
close
Clojure Polymorphism

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)
close
close

Multimethods

You could define the abstraction with multimethods:

1 (ns stadig.storage.methods

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

3

4 (defmulti get :backend)

5 (defmulti put :backend)

6 (defmulti delete :backend)

7 (defmulti close :backend)

Implemented them for each backend:

1 (ns stadig.storage.s3

2   (:require

3    [aws.sdk.s3 :as s3]

4    [stadig.storage.methods :as methods]))

5

6 (defmethod methods/get :s3

7   [this bucket key]

8   (when-not bucket

9     (throw (ex-info "Expected bucket" {:type ::bucket-error})))

10   (s3/get-object this bucket key))

11

12 (defmethod methods/put :s3

13   [this bucket key value]

14   (when-not bucket

15     (throw (ex-info "Expected bucket" {:type ::bucket-error})))

16   (s3/put-object this bucket key value)...

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Clojure Polymorphism
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon