-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
(ns river.examples.monadic | ||
(:use [river.core] | ||
(:use [river.core]) | ||
(:require [river.seq :as rs] | ||
[river.io :as rio])) | ||
[river.io :as rio])) | ||
|
||
(def drop-and-head | ||
(do-consumer | ||
; ^ allows you to create a new consumer using | ||
; a monadic notation as in clojure.algo.monads | ||
[_ (rs/drop-while #(< % 5)) | ||
; ^ drops from the stream until the condition is met | ||
b rs/first] | ||
; ^ gets the first element after the dropping is done | ||
b)) | ||
|
||
(println (run> (rs/produce-seq (range -20 20)) | ||
drop-and-head)) | ||
(defn -main [] | ||
(println (run | ||
; ^ function to execute producers/consumers | ||
(rs/produce-seq (range -20 20)) | ||
; ^ produce a stream of numbers from a seq | ||
drop-and-head))) | ||
; drops until < 5 and then gives the first element found | ||
; (in this case 6) |
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