forked from functional-koans/clojure-koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address changes to PR adding threading forms
- Loading branch information
Showing
3 changed files
with
19 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
(ns koans.26-transducers | ||
(:require [koan-engine.core :refer :all])) | ||
|
||
(def xfms | ||
(def example-transducer | ||
(map inc)) | ||
|
||
(def transforms | ||
(comp (map inc) | ||
(filter even?))) | ||
(filter even?))) | ||
|
||
(meditations | ||
"Consider that sequence operations can be used as transducers" | ||
"A sequence operation with only one argument often returns a transducer" | ||
(= __ | ||
(sequence example-transducer [1 2 3])) | ||
|
||
"Consider that sequence operations can be composed as transducers" | ||
(= __ | ||
(transduce xfms conj [1 2 3])) | ||
(transduce transforms conj [1 2 3])) | ||
|
||
"We can do this eagerly" | ||
(= __ | ||
(into [] xfms [1 2 3])) | ||
(into [] transforms [1 2 3])) | ||
|
||
"Or lazily" | ||
(= __ | ||
(sequence xfms [1 2 3])) | ||
(sequence transforms [1 2 3])) | ||
|
||
"The transduce function can combine mapping and reduction" | ||
(= __ | ||
(transduce xfms + [1 2 3]))) | ||
(transduce transforms + [1 2 3]))) |