New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More Prelude cleanup: #10
Conversation
stephencelis
commented
Jun 21, 2017
- More Array → Sequence polymorphism
- More Either conformances
- Separate Semigroup from Monoid
- More operator categorization
- More Array -> Sequence polymorphism - More Either conformances - Separate Semigroup from Monoid - More operator categorization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated but fun changes.
@@ -7,12 +7,6 @@ public func <*> <A, B> (fs: [(A) -> B], xs: [A]) -> [B] { | |||
return fs.flatMap { f in xs.map(f) } | |||
} | |||
|
|||
public func foldMap<A, M: Monoid>(_ f: @escaping (A) -> M) -> ([A]) -> M { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generalizing things here against Sequence
.
@@ -4,12 +4,12 @@ public enum Either<L, R> { | |||
} | |||
|
|||
extension Either { | |||
public func either<A>(_ f: (L) -> A, _ g: (R) -> A) -> A { | |||
public func either<A>(_ l2a: (L) -> A, _ r2a: (R) -> A) -> A { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming. I wish I had a clear path here and didn't care. 😶
} | ||
} | ||
|
||
// MARK: - Extend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of fun stuff here, but Extend
is a new one.
@@ -8,18 +8,10 @@ public func concat<S: Sequence>(_ xs: S) -> S.Element where S.Element: Monoid { | |||
|
|||
extension String: Monoid { | |||
public static let e = "" | |||
|
|||
public static func <>(lhs: String, rhs: String) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved append
to Semigroup
.
} | ||
} | ||
|
||
public struct Sum<A: Numeric> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno if we want Factor
, First
, Last
, Min
, Max
, and other wrappers, but may be useful and fun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Stuff we may use more generally: Endo
, Const
, Id
…)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all good stuff!
one thing I've wanted in my css work is an instance version of monoid's concat
. I'm often getting long chains of transformations, ending with an array of monoid values, that I then just want to .concat()
.
Added! And merging! |