Skip to content
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

Merged
merged 2 commits into from Jun 22, 2017
Merged

More Prelude cleanup: #10

merged 2 commits into from Jun 22, 2017

Conversation

stephencelis
Copy link
Member

  • 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
Copy link
Member Author

@stephencelis stephencelis left a 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 {
Copy link
Member Author

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 {
Copy link
Member Author

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
Copy link
Member Author

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 {
Copy link
Member Author

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> {
Copy link
Member Author

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.

Copy link
Member Author

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…)

Copy link
Member

@mbrandonw mbrandonw left a 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().

@stephencelis
Copy link
Member Author

Added! And merging!

@stephencelis stephencelis merged commit 51cf446 into master Jun 22, 2017
@stephencelis stephencelis deleted the more-prelude-cleanup branch June 22, 2017 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants