Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: coalton-lang/coalton
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a93004d7baecc955b837d5966f33bc4a80ca2622
Choose a base ref
..
head repository: coalton-lang/coalton
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 246ed64dfcefbb1baeece4a069e87305afe3a201
Choose a head ref
Showing with 25 additions and 3 deletions.
  1. +14 −3 library/classes.lisp
  2. +11 −0 library/iterator.lisp
17 changes: 14 additions & 3 deletions library/classes.lisp
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@
#:>> #:join
#:MonadFail #:fail
#:Alternative #:alt #:empty
#:Foldable #:fold #:foldr #:mconcat
#:Foldable #:fold #:foldr #:mconcat #:mconcatmap
#:mcommute?
#:Traversable #:traverse
#:Bifunctor #:bimap #:map-fst #:map-snd
#:sequence
@@ -233,9 +234,19 @@
(foldr "A right non-tail-recursive fold." ((:elt -> :accum -> :accum) -> :accum -> :container :elt -> :accum)))

(declare mconcat ((Foldable :f) (Monoid :a) => :f :a -> :a))
(define mconcat
(define (mconcat a)
"Fold a container of monoids into a single element."
(fold <> mempty))
(fold <> mempty a))

(declare mconcatmap ((Foldable :f) (Monoid :a) => (:b -> :a) -> :f :b -> :a))
(define (mconcatmap f a)
"Map a container to a container of monoids, and then fold that container into a single element."
(fold (fn (a b) (<> a (f b))) mempty a))

(declare mcommute? ((Eq :a) (Semigroup :a) => :a -> :a -> Boolean))
(define (mcommute? a b)
"Does `a <> b` equal `b <> a`?"
(== (<> a b) (<> b a)))

(define-class (Traversable :t)
(traverse (Applicative :f => (:a -> :f :b) -> :t :a -> :f (:t :b))))
11 changes: 11 additions & 0 deletions library/iterator.lisp
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@
#:take!
#:flatten!
#:flat-map!
#:mconcat!
#:mconcatmap!
#:chain!
#:remove-duplicates! ; defined in library/hashtable.lisp
#:pair-with!
@@ -423,6 +425,15 @@ interleaving. (interleave empty ITER) is equivalent to (id ITER)."
"Flatten! wrapped around map."
(flatten! (map func iter)))

(declare mconcat! ((Monoid :a) => (Iterator :a) -> :a))
(define (mconcat! iter)
"Fold an iterator of monoids into a single element."
(fold! <> mempty iter))

(declare mconcatmap! ((Monoid :a) => (:b -> :a) -> (Iterator :b) -> :a))
(define (mconcatmap! func iter)
"Map an iterator to an iterator of monoids, and then fold that iterator into a single element."
(fold! <> mempty (map func iter)))

(declare pair-with! ((:key -> :value) -> Iterator :key -> Iterator (Tuple :key :value)))
(define (pair-with! func keys)