aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/concurrency/frp.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/concurrency/frp.lux')
-rw-r--r--stdlib/source/lux/concurrency/frp.lux84
1 files changed, 42 insertions, 42 deletions
diff --git a/stdlib/source/lux/concurrency/frp.lux b/stdlib/source/lux/concurrency/frp.lux
index 538bbdcbd..a1839850d 100644
--- a/stdlib/source/lux/concurrency/frp.lux
+++ b/stdlib/source/lux/concurrency/frp.lux
@@ -13,22 +13,22 @@
(.. ["&" promise]))
## [Types]
-(type: #export (Chan a)
+(type: #export (Channel a)
{#;doc "An asynchronous channel of values which may be closed.
Reading from a channel does not remove the read piece of data, as it can still be accessed if you have an earlier node of the channel."}
- (&;Promise (Maybe [a (Chan a)])))
+ (&;Promise (Maybe [a (Channel a)])))
## [Syntax]
-(syntax: #export (chan [type s;any])
- {#;doc (doc "Makes an uninitialized Chan (in this case, of Unit)."
- (chan Unit))}
- (wrap (list (` (: (Chan (~ type))
+(syntax: #export (channel [type s;any])
+ {#;doc (doc "Makes an uninitialized Channel (in this case, of Nat)."
+ (channel Nat))}
+ (wrap (list (` (: (Channel (~ type))
(&;promise' #;None))))))
## [Values]
(def: #export (filter p xs)
- (All [a] (-> (-> a Bool) (Chan a) (Chan a)))
+ (All [a] (-> (-> a Bool) (Channel a) (Channel a)))
(do &;Monad<Promise>
[?x+xs xs]
(case ?x+xs
@@ -39,16 +39,16 @@
(def: #export (write value target)
{#;doc "Write to a channel, so long as it's still open."}
- (All [a] (-> a (Chan a) (IO (Maybe (Chan a)))))
+ (All [a] (-> a (Channel a) (IO (Maybe (Channel a)))))
(case (&;poll target)
- (^template [<case> <chan-to-write>]
+ (^template [<case> <channel-to-write>]
<case>
(do Monad<IO>
- [#let [new-tail (chan ($ +0))]
- done? (&;resolve (#;Some [value new-tail]) <chan-to-write>)]
+ [#let [new-tail (channel ($ +0))]
+ done? (&;resolve (#;Some [value new-tail]) <channel-to-write>)]
(if done?
(wrap (#;Some new-tail))
- (write value <chan-to-write>))))
+ (write value <channel-to-write>))))
([#;None target]
[(#;Some (#;Some [_ target'])) target'])
@@ -57,15 +57,15 @@
))
(def: #export (close target)
- (All [a] (-> (Chan a) (IO Bool)))
+ (All [a] (-> (Channel a) (IO Bool)))
(case (&;poll target)
- (^template [<case> <chan-to-write>]
+ (^template [<case> <channel-to-write>]
<case>
(do Monad<IO>
- [done? (&;resolve #;None <chan-to-write>)]
+ [done? (&;resolve #;None <channel-to-write>)]
(if done?
(wrap true)
- (close <chan-to-write>))))
+ (close <channel-to-write>))))
([#;None target]
[(#;Some (#;Some [_ target'])) target'])
@@ -74,7 +74,7 @@
))
(def: (pipe' input output)
- (All [a] (-> (Chan a) (Chan a) (&;Promise Unit)))
+ (All [a] (-> (Channel a) (Channel a) (&;Promise Unit)))
(do &;Monad<Promise>
[?x+xs input]
(case ?x+xs
@@ -88,7 +88,7 @@
(def: #export (pipe input output)
{#;doc "Copy/pipe the contents of a channel on to another."}
- (All [a] (-> (Chan a) (Chan a) (&;Promise Unit)))
+ (All [a] (-> (Channel a) (Channel a) (&;Promise Unit)))
(do &;Monad<Promise>
[_ (pipe' input output)]
(exec (io;run (close output))
@@ -96,8 +96,8 @@
(def: #export (merge xss)
{#;doc "Fuse all the elements in a list of channels by piping them onto a new output channel."}
- (All [a] (-> (List (Chan a)) (Chan a)))
- (let [output (chan ($ +0))]
+ (All [a] (-> (List (Channel a)) (Channel a)))
+ (let [output (channel ($ +0))]
(exec (do &;Monad<Promise>
[_ (mapM @ (function [input] (pipe' input output)) xss)]
(exec (io;run (close output))
@@ -106,7 +106,7 @@
(def: #export (fold f init xs)
{#;doc "Asynchronous fold over channels."}
- (All [a b] (-> (-> b a (&;Promise a)) a (Chan b) (&;Promise a)))
+ (All [a b] (-> (-> b a (&;Promise a)) a (Channel b) (&;Promise a)))
(do &;Monad<Promise>
[?x+xs xs]
(case ?x+xs
@@ -117,7 +117,7 @@
(def: #export (folds f init xs)
{#;doc "A channel of folds."}
- (All [a b] (-> (-> b a (&;Promise a)) a (Chan b) (Chan a)))
+ (All [a b] (-> (-> b a (&;Promise a)) a (Channel b) (Channel a)))
(do &;Monad<Promise>
[?x+xs xs]
(case ?x+xs
@@ -127,7 +127,7 @@
(folds f init' xs')))))
(def: (distinct' eq last-one xs)
- (All [a] (-> (Eq a) a (Chan a) (Chan a)))
+ (All [a] (-> (Eq a) a (Channel a) (Channel a)))
(let [(^open) eq]
(do &;Monad<Promise>
[?x+xs xs]
@@ -139,7 +139,7 @@
(def: #export (distinct eq xs)
{#;doc "Multiple consecutive equal values in the input channel will just be single value in the output channel."}
- (All [a] (-> (Eq a) (Chan a) (Chan a)))
+ (All [a] (-> (Eq a) (Channel a) (Channel a)))
(let [(^open) eq]
(do &;Monad<Promise>
[?x+xs xs]
@@ -149,7 +149,7 @@
(def: #export (consume xs)
{#;doc "Reads the entirety of a channel's contents and returns them as a list."}
- (All [a] (-> (Chan a) (&;Promise (List a))))
+ (All [a] (-> (Channel a) (&;Promise (List a))))
(do &;Monad<Promise>
[?x+xs' xs]
(case ?x+xs'
@@ -162,13 +162,13 @@
(wrap (#;Cons x =xs))))))
(def: #export (once p)
- (All [a] (-> (&;Promise a) (Chan a)))
+ (All [a] (-> (&;Promise a) (Channel a)))
(do &;Monad<Promise>
[x p]
(wrap (#;Some [x (wrap #;None)]))))
(def: #export (poll time action)
- (All [a] (-> Nat (IO (Maybe a)) (Chan a)))
+ (All [a] (-> Nat (IO (Maybe a)) (Channel a)))
(do &;Monad<Promise>
[?output (&;future action)]
(case ?output
@@ -181,7 +181,7 @@
(wrap (#;Some [head (poll time action)]))))))
(def: #export (periodic time value)
- (All [a] (-> Nat a (Chan a)))
+ (All [a] (-> Nat a (Channel a)))
(do &;Monad<Promise>
[]
(wrap (#;Some [value (do @
@@ -189,7 +189,7 @@
(periodic time value))]))))
(def: #export (sequential time xs)
- (All [a] (-> Nat (List a) (Chan a)))
+ (All [a] (-> Nat (List a) (Channel a)))
(do &;Monad<Promise>
[]
(case xs
@@ -202,7 +202,7 @@
(sequential time xs'))])))))
(def: #export (cycle time values)
- (All [a] (-> Nat (List a) (Chan a)))
+ (All [a] (-> Nat (List a) (Channel a)))
(do &;Monad<Promise>
[]
(case values
@@ -231,7 +231,7 @@
xs'))
(def: #export (sliding-window max inputs)
- (All [a] (-> Nat (Chan a) (Chan (List a))))
+ (All [a] (-> Nat (Channel a) (Channel (List a))))
(let [(^open) &;Monad<Promise>]
(folds (function [input window]
(let [window' (L/append window (list input))]
@@ -242,7 +242,7 @@
inputs)))
(def: #export (iterate f init)
- (All [a] (-> (-> a (&;Promise (Maybe a))) a (Chan a)))
+ (All [a] (-> (-> a (&;Promise (Maybe a))) a (Channel a)))
(do &;Monad<Promise>
[]
(wrap (#;Some [init (do @
@@ -255,7 +255,7 @@
(iterate f init')))]))))
(def: #export (sample time inputs)
- (All [a] (-> Nat (Chan a) (Chan a)))
+ (All [a] (-> Nat (Channel a) (Channel a)))
(do &;Monad<Promise>
[?h+t inputs]
(case ?h+t
@@ -276,7 +276,7 @@
(wrap (#;Some [value (sample time next-inputs)]))))))
## [Structures]
-(struct: #export _ (Functor Chan)
+(struct: #export _ (Functor Channel)
(def: (map f xs)
(:: &;Functor<Promise> map
(function [?x+xs]
@@ -285,26 +285,26 @@
(#;Some [x xs']) (#;Some [(f x) (map f xs')])))
xs)))
-(struct: #export _ (Applicative Chan)
- (def: functor Functor<Chan>)
+(struct: #export _ (Applicative Channel)
+ (def: functor Functor<Channel>)
(def: (wrap a)
(let [(^open) &;Monad<Promise>]
(wrap (#;Some [a (wrap #;None)]))))
(def: (apply ff fa)
- (let [fb (chan ($ +1))]
- (exec (let [(^open) Functor<Chan>]
+ (let [fb (channel ($ +1))]
+ (exec (let [(^open) Functor<Channel>]
(map (function [f] (pipe (map f fa) fb))
ff))
fb))))
-(struct: #export _ (Monad Chan)
- (def: applicative Applicative<Chan>)
+(struct: #export _ (Monad Channel)
+ (def: applicative Applicative<Channel>)
(def: (join mma)
- (let [output (chan ($ +0))]
- (exec (let [(^open) Functor<Chan>]
+ (let [output (channel ($ +0))]
+ (exec (let [(^open) Functor<Channel>]
(map (function [ma]
(pipe ma output))
mma))