Skip to content

Commit 99d279f

Browse files
committed
Add partial section on References
1 parent 1520bbb commit 99d279f

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

index.adoc

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ project.
2525

2626
WARNING: This documentation assumes knowledge of Clojure.
2727

28-
== Setup
28+
== Project Setup
2929

3030
This section will cover setting up a new Duct project. You'll first need
3131
to ensure that the
@@ -270,3 +270,39 @@ $ NAME=Clojurist duct --main
270270
✓ Initiating system...
271271
Hello Clojurist
272272
----
273+
274+
=== References
275+
276+
A Duct system can have multiple components, and components can
277+
communicate via references, which are divided into *refs* and
278+
*refsets*. A ref references exactly one other component; a refset
279+
references zero or more components.
280+
281+
To demonstrate how refs work, we'll divide our '`Hello World`'
282+
application into two functions.
283+
284+
[,clojure]
285+
----
286+
(ns tutorial.print)
287+
288+
(defn printer [{:keys [prefix]}]
289+
(partial println prefix))
290+
291+
(defn hello [{:keys [name output]}]
292+
(output "Hello" name))
293+
----
294+
295+
The `printer` component returns a function that prints its arguments
296+
with a custom prefix. The `hello` component takes a `:output` option
297+
that it uses to output a message. In order to connect these two
298+
components in the `duct.edn` file, we use the `#ig/ref` data reader.
299+
300+
[,clojure]
301+
----
302+
{:system
303+
{:tutorial.print/printer
304+
{:prefix ">>"}
305+
:tutorial.print/hello
306+
{:name "World"
307+
:output #ig/ref :tutorial.print/printer}}}
308+
----

0 commit comments

Comments
 (0)