-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Virtual Future Applicative Engine (#31)
* Remove all `clojure.core` private function invocations * Add eval-key-channel for virtual future engine * applicative engine for virtual futures * conditionally require ns * fun with namespaces * linter * delete the test * changelog --------- Co-authored-by: Alex Redington <[email protected]> Co-authored-by: Sophia Velten de Melo <[email protected]>
- Loading branch information
1 parent
9fd3c41
commit 49bc3e1
Showing
8 changed files
with
87 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(ns nodely.engine.applicative.virtual-future | ||
(:require | ||
[cats.protocols :as mp] | ||
[nodely.engine.applicative.protocols :as protocols] | ||
[nodely.engine.virtual-future :as virtual-future :refer [vfuture]]) | ||
(:import | ||
nodely.engine.virtual_future.GreenFuture)) | ||
|
||
(declare context) | ||
|
||
(extend-type GreenFuture | ||
mp/Contextual | ||
(-get-context [_] context) | ||
|
||
mp/Extract | ||
(-extract [it] | ||
(try (deref it) | ||
(catch java.util.concurrent.ExecutionException e | ||
(throw (.getCause e)))))) | ||
|
||
(def context | ||
(reify | ||
mp/Context | ||
protocols/RunNode | ||
(-apply-fn [_ f mv] | ||
(vfuture (f (deref mv)))) | ||
|
||
mp/Functor | ||
(-fmap [mn f mv] | ||
(vfuture (f (deref mv)))) | ||
|
||
mp/Monad | ||
(-mreturn [_ v] | ||
(vfuture v)) | ||
|
||
(-mbind [mn mv f] | ||
(vfuture (let [v (deref mv)] | ||
(deref (f v))))) | ||
|
||
mp/Applicative | ||
(-pure [_ v] | ||
(vfuture v)) | ||
|
||
(-fapply [_ pf pv] | ||
(vfuture (let [f (deref pf) | ||
v (deref pv)] | ||
(f v)))))) |
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