-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
a02af15
commit baf7ea1
Showing
5 changed files
with
161 additions
and
3 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,72 @@ | ||
... 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) | ||
[abstract | ||
[functor (.only Functor)] | ||
["[0]" monad (.only Monad) | ||
["/" free]]] | ||
["[0]" function] | ||
[data | ||
[collection | ||
["[0]" list] | ||
["[0]" sequence (.only Sequence)]]] | ||
["[0]" type]]]) | ||
|
||
... https://en.wikipedia.org/wiki/Iterator | ||
... https://en.wikipedia.org/wiki/Generator_(computer_programming) | ||
... https://en.wikipedia.org/wiki/Stream_(computing) | ||
(every (Yield it !) | ||
[[it] (-> [] !)]) | ||
|
||
(the yield_functor | ||
(for_any (_ it) | ||
(Functor (Yield it))) | ||
(implementation | ||
(the (each on [input next]) | ||
[input (|>> next on)]))) | ||
|
||
(every .public (Stream yield it) | ||
(/.Free (..Yield yield) it)) | ||
|
||
(the .public monad | ||
(for_any (_ yield) | ||
(Monad (Stream yield))) | ||
(/.monad ..yield_functor)) | ||
|
||
(the .public functor | ||
(for_any (_ yield) | ||
(Functor (Stream yield))) | ||
(its monad.functor ..monad)) | ||
|
||
(the .public (sequence it) | ||
(for_any (_ yield it) | ||
(-> (Stream yield it) | ||
[(Sequence yield) it])) | ||
(loop (next [yield (type.sharing [yield it] | ||
(is (Stream yield it) | ||
it) | ||
(is (Sequence yield) | ||
sequence.empty)) | ||
it it]) | ||
(when it | ||
{/.#Pure it} | ||
[yield it] | ||
|
||
{/.#Impure [item after]} | ||
(next (sequence.suffix item yield) | ||
(after []))))) | ||
|
||
(the .public (one it) | ||
(for_any (_ it) | ||
(-> it | ||
(Stream it Any))) | ||
{/.#Impure [[it] (function.constant {/.#Pure []})]}) | ||
|
||
(the .public many | ||
(for_any (_ it) | ||
(-> (List it) | ||
(Stream it Any))) | ||
(list.each' ..monad ..one)) |
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,77 @@ | ||
... 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) | ||
[abstract | ||
[equivalence (.only Equivalence)] | ||
[functor (.only Functor)] | ||
["[0]" monad (.only Monad do) | ||
["[1]T" \\test]] | ||
["[0]" functor | ||
["[1]T" \\test (.only Comparison)]]] | ||
[data | ||
["[0]" product] | ||
[collection | ||
["[0]" sequence (.only sequence)]]] | ||
[math | ||
["[0]" random] | ||
[number | ||
["[0]" natural]]] | ||
[test | ||
["_" property (.only Test)]]]] | ||
[\\library | ||
["[0]" /]]) | ||
|
||
(the (comparison yield_equivalence) | ||
(for_any (_ yield) | ||
(-> (Equivalence yield) | ||
(Comparison (/.Stream yield)))) | ||
(function (_ value_equivalence reference it) | ||
(let [[reference_yield reference_value] (/.sequence reference) | ||
[it_yield it_value] (/.sequence it)] | ||
(and (by (sequence.equivalence yield_equivalence) = reference_yield it_yield) | ||
(by value_equivalence = reference_value reference_value))))) | ||
|
||
(the .public test | ||
Test | ||
(<| (_.covering /._) | ||
(do random.monad | ||
[_0 random.natural | ||
_1 random.natural | ||
_2 random.natural]) | ||
(_.for [/.Stream]) | ||
(all _.and | ||
(_.for [/.functor] | ||
(functorT.spec (by /.monad in) (..comparison natural.equivalence) /.functor)) | ||
(_.for [/.monad] | ||
(monadT.spec (by /.monad in) (..comparison natural.equivalence) /.monad)) | ||
|
||
(<| (_.for [/.sequence]) | ||
(all _.and | ||
(_.coverage [/.one] | ||
(|> (do /.monad | ||
[_ (/.one _1) | ||
|
||
_ (/.one _2) | ||
_ (/.one _2)] | ||
(in [])) | ||
/.sequence | ||
product.left | ||
(by (sequence.equivalence natural.equivalence) = | ||
(sequence _1 | ||
_2 _2)))) | ||
(_.coverage [/.many] | ||
(|> (do /.monad | ||
[_ (/.many (list)) | ||
_ (/.many (list _1)) | ||
_ (/.many (list _2 _2))] | ||
(in [])) | ||
/.sequence | ||
product.left | ||
(by (sequence.equivalence natural.equivalence) = | ||
(sequence _1 | ||
_2 _2)))) | ||
)) | ||
))) |