aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/concurrency/task.lux
diff options
context:
space:
mode:
authorEduardo Julian2018-12-04 19:10:43 -0400
committerEduardo Julian2018-12-04 19:10:43 -0400
commit73120f5cc97224c2a5c961b4aa881738cc78e2af (patch)
treec45bc39a93856633cc9bb7da9d7d7245e652c231 /stdlib/source/lux/concurrency/task.lux
parentccdac3e7ae689cfe9f8fe2211527ec37023a2a34 (diff)
Some refactoring.
Diffstat (limited to 'stdlib/source/lux/concurrency/task.lux')
-rw-r--r--stdlib/source/lux/concurrency/task.lux60
1 files changed, 31 insertions, 29 deletions
diff --git a/stdlib/source/lux/concurrency/task.lux b/stdlib/source/lux/concurrency/task.lux
index f3043ce9b..c03ab7647 100644
--- a/stdlib/source/lux/concurrency/task.lux
+++ b/stdlib/source/lux/concurrency/task.lux
@@ -1,55 +1,57 @@
(.module:
[lux #*
- [data ["E" error]]
[control
- ["F" functor]
- ["A" apply]
- monad
+ [functor (#+ Functor)]
+ [apply (#+ Apply)]
+ [monad (#+ Monad do)]
["ex" exception (#+ Exception)]]
- [concurrency ["P" promise]]
- ["." macro ["s" syntax (#+ syntax: Syntax)]]
- ])
+ [data
+ ["." error (#+ Error)]]
+ ["." macro
+ ["s" syntax (#+ syntax: Syntax)]]]
+ [//
+ ["." promise (#+ Promise)]])
(type: #export (Task a)
- (P.Promise (E.Error a)))
+ (Promise (Error a)))
(def: #export (fail error)
(All [a] (-> Text (Task a)))
- (:: P.Monad<Promise> wrap (#E.Error error)))
+ (:: promise.Monad<Promise> wrap (#error.Error error)))
(def: #export (throw exception message)
(All [e a] (-> (Exception e) e (Task a)))
- (:: P.Monad<Promise> wrap
+ (:: promise.Monad<Promise> wrap
(ex.throw exception message)))
(def: #export (return value)
(All [a] (-> a (Task a)))
- (:: P.Monad<Promise> wrap (#E.Success value)))
+ (:: promise.Monad<Promise> wrap (#error.Success value)))
(def: #export (try computation)
- (All [a] (-> (Task a) (Task (E.Error a))))
- (:: P.Functor<Promise> map (|>> #E.Success) computation))
+ (All [a] (-> (Task a) (Task (Error a))))
+ (:: promise.Functor<Promise> map (|>> #error.Success) computation))
-(structure: #export _ (F.Functor Task)
+(structure: #export _ (Functor Task)
(def: (map f fa)
- (:: P.Functor<Promise> map
+ (:: promise.Functor<Promise> map
(function (_ fa')
(case fa'
- (#E.Error error)
- (#E.Error error)
+ (#error.Error error)
+ (#error.Error error)
- (#E.Success a)
- (#E.Success (f a))))
+ (#error.Success a)
+ (#error.Success (f a))))
fa)))
-(structure: #export _ (A.Apply Task)
+(structure: #export _ (Apply Task)
(def: functor Functor<Task>)
(def: (apply ff fa)
- (do P.Monad<Promise>
+ (do promise.Monad<Promise>
[ff' ff
fa' fa]
- (wrap (do E.Monad<Error>
+ (wrap (do error.Monad<Error>
[f ff'
a fa']
(wrap (f a)))))))
@@ -60,21 +62,21 @@
(def: wrap return)
(def: (join mma)
- (do P.Monad<Promise>
+ (do promise.Monad<Promise>
[mma' mma]
(case mma'
- (#E.Error error)
- (wrap (#E.Error error))
+ (#error.Error error)
+ (wrap (#error.Error error))
- (#E.Success ma)
+ (#error.Success ma)
ma))))
(syntax: #export (task {type s.any})
{#.doc (doc "Makes an uninitialized Task (in this example, of Any)."
(task Any))}
(wrap (list (` (: (..Task (~ type))
- (P.promise #.None))))))
+ (promise.promise #.None))))))
(def: #export (from-promise promise)
- (All [a] (-> (P.Promise a) (Task a)))
- (:: P.Functor<Promise> map (|>> #E.Success) promise))
+ (All [a] (-> (Promise a) (Task a)))
+ (:: promise.Functor<Promise> map (|>> #error.Success) promise))