Skip to content

Commit

Permalink
Added reducer and transducer as alternatives to Stream and Filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Mar 21, 2024
1 parent 06c182d commit 22efb27
Show file tree
Hide file tree
Showing 42 changed files with 517 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [Public APIs](https://publicapis.dev/)
0. [REST vs. gRPC](https://cerbos.dev/blog/rest-vs-grpc)
0. [How to Use Abstraction to Kill Your API - Jonathan Marler - Software You Can Love Vancouver 2023](https://www.youtube.com/watch?v=aPWFLkHRIAQ)
0. [ApiVault](https://apivault.dev/)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [Rich: a Python library for rich text and beautiful formatting in the terminal](https://github.com/Textualize/rich)
0. [Terminals Are Sexy(https://terminalsare.sexy/)
0. [Contextual CLIs](https://garnix.io/blog/contextual-cli)
0. [Textual](https://github.com/willmcgugan/textual)
Expand Down
1 change: 1 addition & 0 deletions documentation/bookmark/mathematics/proof.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [The Mechanics of Proof](https://hrmacbeth.github.io/math2001/index.html)
0. [The mechanics of proof](https://hrmacbeth.github.io/math2001/)
0. [Basics of Proofs](https://theory.stanford.edu/~jvondrak/MATH108-2017/Proofs.pdf)
0. [Book of Proof](https://www.people.vcu.edu/~rhammack/BookOfProof/BookOfProof.pdf)
Expand Down
1 change: 1 addition & 0 deletions documentation/bookmark/security/authentication.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [The Copenhagen Book](https://thecopenhagenbook.com/)
0. [Secure Quick Reliable Login](https://www.grc.com/sqrl/sqrl.htm)
0. [Hanko](https://www.hanko.io/)
0. [Auth.js: Authentication for the Web.](https://authjs.dev/)
Expand Down
3 changes: 2 additions & 1 deletion stdlib/source/library/lux/abstract/functor.lux
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
(.using
[library
[lux (.except function)
["//" algorithm]]])
[function
["//" polytypism]]]])

(every .public (Functor !)
(Interface
Expand Down
5 changes: 3 additions & 2 deletions stdlib/source/library/lux/abstract/functor/effect.lux
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
(.using
[library
[lux (.except Or or)
["[0]" algorithm]]]
[function
["[0]" polytypism]]]]
["[0]" // (.only Functor)])

(every .public (Effect input output !)
Expand All @@ -18,7 +19,7 @@
[input (|>> next on)])))

(the .public Or
algorithm.Sum)
polytypism.Sum)

(the .public or
//.sum)
6 changes: 3 additions & 3 deletions stdlib/source/library/lux/data/collection/array.lux
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
[monoid (.only Monoid)]
[functor (.only Functor)]
[equivalence (.only Equivalence)]]
[algorithm
[mix (.only Mix)]]
[error
["[0]" try (.only Try)]]
[function
[predicate (.only Predicate)]]
[predicate (.only Predicate)]
[polytypism
[mix (.only Mix)]]]
[data
[collection
["[0]" stack (.use "[1]#[0]" functor)]]]
Expand Down
30 changes: 26 additions & 4 deletions stdlib/source/library/lux/data/collection/list.lux
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
[monoid (.only Monoid)]
[functor (.only Functor)]
[monad (.only Monad)]]
[algorithm
[mix (.only Mix)]]
[error (.only error)
["[0]" try (.only Try)]]
[data
["[0]" product]]
[function
[predicate (.only Predicate)]]
[predicate (.only Predicate)]
[polytypism
[mix (.only Mix)]]]
[math
[number
["n" natural]]]]]
Expand Down Expand Up @@ -416,7 +416,7 @@
size_of_1 (/.size _1)
size (n.minor size_of_0 size_of_1)]
(..abstraction
(if (n.= size_of_0 size)
(if (same? size_of_0 size)
(/.mix (function (_ @ _0 it)
(/.has! @ [_0 (/.item @ _1)] it))
(/.empty size)
Expand Down Expand Up @@ -530,3 +530,25 @@
(-> (Equivalence it) (List it) it
Bit))
(any? (= candidate) context))

(the .public (interposed delimiter it)
(for_any (_ it)
(-> it (List it)
(List it)))
(when (..size it)
0 it
1 it

size
(let [last (-- size)
new_size (n.+ size last)]
(..abstraction
(/.mix (function (_ @ value it)
(let [@' (n.* 2 @)]
(if (n.= last @)
(/.has! @' value it)
(|> it
(/.has! @' value)
(/.has! (++ @') delimiter)))))
(/.empty new_size)
(..reification it))))))
6 changes: 3 additions & 3 deletions stdlib/source/library/lux/data/collection/sequence.lux
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
[equivalence (.only Equivalence)]
[monoid (.only Monoid)]
["<>" projection]]
[algorithm
[mix (.only Mix)]]
[control
["[0]" maybe (.use "[1]#[0]" functor)]]
[error
["[0]" try (.only Try)]
["[0]" exception (.only Exception)]]
[function
[predicate (.only Predicate)]]
[predicate (.only Predicate)]
[polytypism
[mix (.only Mix)]]]
[data
["[0]" product]
[collection
Expand Down
6 changes: 3 additions & 3 deletions stdlib/source/library/lux/data/collection/stack.lux
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
["[0]" functor (.only Functor)]
["[0]" monad (.only Monad do)]
["[0]" enum]]
[algorithm
[mix (.only Mix)]]
[error (.only error)
["[0]" try (.only Try)]]
[function
[predicate (.only Predicate)]]
[predicate (.only Predicate)]
[polytypism
[mix (.only Mix)]]]
[data
["[0]" bit]
["[0]" product]]
Expand Down
5 changes: 3 additions & 2 deletions stdlib/source/library/lux/data/collection/tree.lux
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
[equivalence (.only Equivalence)]
[monad (.only do)]
["<>" projection]]
[algorithm
[mix (.only Mix)]]
[function
[polytypism
[mix (.only Mix)]]]
[data
[collection
["[0]" stack (.use "[1]#[0]" monad mix)]]]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions stdlib/source/library/lux/transduction.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
... 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)]])

... https://clojure.org/reference/reducers
... https://clojure.org/news/2012/05/08/reducers
... https://clojure.org/news/2012/05/15/anatomy-of-reducer
(every .public (Reduction piece whole)
(-> piece whole
whole))

... https://clojure.org/reference/transducers
... https://en.wikipedia.org/wiki/Transduction
(every .public (Transduction to_consume to_produce
outer_whole inner_whole)
(-> (Reduction to_produce inner_whole)
(Reduction to_consume outer_whole)))
85 changes: 85 additions & 0 deletions stdlib/source/library/lux/transduction/pure.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
... 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 and)
["[0]" function (.only)
[predicate (.only Predicate)]
[polytypism
[mix (.only Mix)]]]
[error
["[0]" try]]
[data
[collection
["[0]" dictionary (.only Dictionary)]]]]]
["[0]" //])

(every .public (Transduction to_consume to_produce whole)
(//.Transduction to_consume to_produce
whole whole))

(the .public nothing
(for_any (_ it)
(Transduction it it))
function.identity)

(the .public and
(for_any (_ to_consume in_transit to_produce)
(-> (Transduction to_consume in_transit) (Transduction in_transit to_produce)
(Transduction to_consume to_produce)))
function.composite)

(the .public (each it)
(for_any (_ to_consume to_produce)
(-> (-> to_consume to_produce)
(Transduction to_consume to_produce)))
(function (_ mix part whole)
(mix (it part) whole)))

(the .public (only ?)
(for_any (_ it)
(-> (Predicate it)
(Transduction it it)))
(function (_ mix part whole)
(if (? part)
(mix part whole)
whole)))

(the .public (many collection::mix)
(for_any (_ collection it)
(-> (Mix collection)
(Transduction (collection it) it)))
(function (_ mix part whole)
(collection::mix mix whole part)))

(the .public maybe
(for_any (_ it)
(Transduction (Maybe it) it))
(function (_ mix part whole)
(when part
{.#Some part}
(mix part whole)

{.#None}
whole)))

(the .public (replaced replacements)
(for_any (_ it)
(-> (Dictionary it it)
(Transduction it it)))
(function (_ mix part whole)
(mix (|> replacements
(dictionary.value part)
(try.else part))
whole)))

(the .public (in_series mix initial
transduction
collection::mix collection)
(for_any (_ collection to_consume to_mix whole)
(-> (//.Reduction to_mix whole) whole
(Transduction to_consume to_mix)
(Mix collection) (collection to_consume)
whole))
(collection::mix (transduction mix) initial collection))
Loading

0 comments on commit 22efb27

Please sign in to comment.