-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
1 parent
cd40bb6
commit 8084df9
Showing
23 changed files
with
511 additions
and
478 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
(.using | ||
[library | ||
[lux (.except Or or) | ||
["[0]" algorithm]]] | ||
["[0]" // (.only Functor)]) | ||
|
||
(every .public (Effect input output !) | ||
[input (-> output !)]) | ||
|
||
(the .public functor | ||
(for_any (_ input output) | ||
(Functor (Effect input output))) | ||
(implementation | ||
(the (each on [input next]) | ||
[input (|>> next on)]))) | ||
|
||
(the .public Or | ||
algorithm.Sum) | ||
|
||
(the .public or | ||
//.sum) |
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,107 @@ | ||
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
(.using | ||
[library | ||
[lux (.except only) | ||
[abstract | ||
[functor (.only Functor) | ||
["//" effect]] | ||
["[0]" monad (.only Monad do) | ||
["/" free]]] | ||
["[0]" function (.only) | ||
[predicate (.only Predicate)]] | ||
[data | ||
[collection | ||
["[0]" list] | ||
["[0]" sequence (.only Sequence)]]] | ||
[macro | ||
["[0]" expansion]]]] | ||
[// | ||
["[0]" stream (.only Stream)]]) | ||
|
||
(the Yield stream.Effect) | ||
|
||
(every (Read it) | ||
(//.Effect [] it)) | ||
|
||
... https://en.wikipedia.org/wiki/Filter_(software) | ||
(every .public (Effect read yield) | ||
(all //.Or | ||
(Read read) | ||
(Yield yield) | ||
)) | ||
|
||
(every .public (Filter read yield) | ||
(/.Free (Effect read yield))) | ||
|
||
(the .public monad | ||
(for_any (_ read yield) | ||
(Monad (Filter read yield))) | ||
(/.monad (all //.or | ||
//.functor | ||
//.functor | ||
))) | ||
|
||
(expansion.let [#Read (these 0 #0) | ||
#Yield (these 0 #1)] | ||
(these (the .public read | ||
(for_any (_ read yield) | ||
(Filter read yield read)) | ||
{/.#Impure {#Read [[] (|>> {/.#Pure})]}}) | ||
|
||
(the .public (yield it) | ||
(for_any (_ read yield) | ||
(-> yield | ||
(Filter read yield Any))) | ||
{/.#Impure {#Yield [[it] (function.constant {/.#Pure []})]}}) | ||
|
||
(the .public (stream filter it) | ||
(for_any (_ read yield it) | ||
(-> (Filter read yield it) (Stream read it) | ||
(Stream yield it))) | ||
(when filter | ||
{/.#Impure {#Read [_ after_read]}} | ||
(when it | ||
{/.#Impure [yield after_stream]} | ||
(stream (after_read yield) (after_stream [])) | ||
|
||
{/.#Pure it} | ||
{/.#Pure it}) | ||
|
||
{/.#Impure {#Yield [item after]}} | ||
{/.#Impure [item (function (_ input) | ||
(stream (after input) it))]} | ||
|
||
{/.#Pure it} | ||
{/.#Pure it}))) | ||
) | ||
|
||
(the .public identity | ||
(for_any (_ it) | ||
(Filter it it Any)) | ||
(loop (next [_ []]) | ||
(do ..monad | ||
[it ..read | ||
_ (..yield it)] | ||
(next [])))) | ||
|
||
(the .public (each on) | ||
(for_any (_ read yield) | ||
(-> (-> read yield) | ||
(Filter read yield Any))) | ||
(do ..monad | ||
[it ..read | ||
_ (..yield (on it))] | ||
(each on))) | ||
|
||
(the .public (only ?) | ||
(for_any (_ it) | ||
(-> (Predicate it) | ||
(Filter it it Any))) | ||
(do ..monad | ||
[it ..read | ||
_ (if (? it) | ||
(..yield it) | ||
(in []))] | ||
(only ?))) |
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
Oops, something went wrong.