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

[WIP] Remove Dependence on Swiftz #21

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
[submodule "Carthage/Checkouts/SwiftCheck"]
path = Carthage/Checkouts/SwiftCheck
url = https://github.com/typelift/SwiftCheck.git
[submodule "Carthage/Checkouts/Swiftz"]
path = Carthage/Checkouts/Swiftz
url = https://github.com/typelift/Swiftz.git
[submodule "Carthage/Checkouts/Operadics"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to remove Swiftz's submodule.

path = Carthage/Checkouts/Operadics
url = https://github.com/typelift/Operadics.git
121 changes: 12 additions & 109 deletions Aquifer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions Aquifer/Auxiliary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// roughly `Pipes.Extras`

import Swiftz

/// Lifts an arrow into a pipe by connecting its inputs to the upstream input and its outputs to the
/// downstream output of the pipe.
public func arr<A, B, R>(f : A -> B) -> Pipe<A, B, R>.T {
Expand All @@ -34,11 +32,6 @@ public func right<A, B, C, R>(p : Pipe<A, B, R>.T) -> Pipe<Either<C, A>, Either<
return rightInner() >~~ for_(p) { v in yield(Either.Right(v)) }
}

infix operator +++ {
associativity left
precedence 180
}

/// Returns a pipe that acts like `+++` from Control.Arrow.
///
/// `.Left` values fed to the pipe's upstream input will appear downstream as `.Left`s that have
Expand Down
47 changes: 33 additions & 14 deletions Aquifer/Basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// roughly `Pipes.Prelude`

import Swiftz

// MARK: - Data.Pipes

/// Returns a `Pipe` that produces the given value then terminates.
Expand Down Expand Up @@ -37,14 +35,14 @@ public func not<FR>() -> Pipe<Bool, Bool, FR>.T {
// MARK: - Data.Monoid

/// Folds the values inside the given pipe using the `Monoid` op.
public func mconcat<V : Monoid>(p : Producer<V, ()>.T) -> V {
return fold(p, stepWith : { $0.op($1) }, initializeWith : V.mempty, extractWith : { $0 })
}
//public func mconcat<V : Monoid>(p : Producer<V, ()>.T) -> V {
// return fold(p, stepWith : { $0.op($1) }, initializeWith : V.mempty, extractWith : { $0 })
//}

/// Mark: - Data.Foldable

/// Returns a representation of the given pipe as a list.
public func toList<V>(p : Producer<V, ()>.T) -> List<V> {
public func toList<V>(p : Producer<V, ()>.T) -> [V] {
return toListRepr(p.repr)
}

Expand Down Expand Up @@ -143,13 +141,13 @@ public func or(p : Producer<Bool, ()>.T) -> Bool {
}

/// Returns the sum of the values in the given pipe.
public func sum<V : NumericType>(p : Producer<V, ()>.T) -> V {
return fold(p, stepWith : { $0.plus($1) }, initializeWith : V.zero, extractWith : { $0 })
public func sum<V : IntegerType>(p : Producer<V, ()>.T) -> V {
return fold(p, stepWith : { $0 + $1 }, initializeWith :0, extractWith : { $0 })
}

/// Returns the product of the values in the given pipe.
public func product<V : NumericType>(p : Producer<V, ()>.T) -> V {
return fold(p, stepWith : { $0.times($1) }, initializeWith : V.one, extractWith : { $0 })
public func product<V : IntegerType>(p : Producer<V, ()>.T) -> V {
return fold(p, stepWith : { $0 * $1 }, initializeWith : 1, extractWith : { $0 })
}

/// Finds the maximum value among all the elements of the given pipe.
Expand Down Expand Up @@ -303,8 +301,29 @@ public func zipWith<V0, V1, V2, R>(p : Producer<V0, R>.T, _ q : Producer<V1, R>.
}

// this seems to required higher-kinded types to implement, even though none appear in its signature
/*public func tee<V, R>(p : Pipe<V, X, R>.T) -> Pipe<V, V, R>.T {
}*/
//public func tee<A, R>(p : Consumer<A, R>.T) -> Pipe<A, A, R>.T {
// let up : State<X, Optional<A>> = (tt >>- { ma in
// switch ma {
// case .None:
// return pure(())
// case .Some(let x):
// return yield(x)
// }
// } >> await() >>- { a in
// return put(.Some(a)) >> pure(a)
// })
// return up >>| (p |>> closed) >>- { r in
// return get() >>- { ma in
// switch ma {
// case .None:
// return pure(())
// case .Some(let x):
// return yield(x)
// }
// }
// return pure(r)
// }
//}

// this seems to required higher-kinded types to implement, even though none appear in its signature
/*public func generalize<UT, UI, DO, FR>(p : Pipe<UI, DO, FR>.T) -> Proxy<UT, UI, UT, DO, FR> {
Expand Down Expand Up @@ -354,10 +373,10 @@ private func lastInner<V>(x : V, _ p : Producer<V, ()>.T) -> V? {
}
}

private func toListRepr<V>(p : ProxyRepr<X, (), (), V, ()>) -> List<V> {
private func toListRepr<V>(p : ProxyRepr<X, (), (), V, ()>) -> [V] {
switch p {
case let .Request(uO, _): return closed(uO())
case let .Respond(dO, fDI): return List(dO(), toListRepr(fDI(())))
case let .Respond(dO, fDI): return [dO()] + toListRepr(fDI(()))
case .Pure(_): return []
}
}
2 changes: 0 additions & 2 deletions Aquifer/Operators.swift → Aquifer/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// roughly `Pipes.Core`

import Swiftz

/// Send a value upstream and block waiting for a reply.
///
/// UO
Expand Down
3 changes: 1 addition & 2 deletions Aquifer/Grouping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//

// roughly `Pipes.Group`

import Swiftz
import Focus

/// A producer that uses the Free Monad Transformer (unrepresentable in Swift) to delimit groupings
/// of produced values.
Expand Down
3 changes: 1 addition & 2 deletions Aquifer/IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

// part of `Pipes.Prelude`

import Foundation
import Swiftz
import class Foundation.NSFileHandle

/// Returns a `Pipe` that reads input from `stdin` line-by-line and terminates on end-of-input.
public func stdinLn() -> Producer<String, ()>.T {
Expand Down
1 change: 0 additions & 1 deletion Aquifer/Parsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

// roughly `Pipes.Parse`

import Swiftz
import Focus

/// Splits the `Producer` into two `Producer`s, where the outer `Producer` is the longest
Expand Down
4 changes: 2 additions & 2 deletions Aquifer/Proxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// roughly `Pipes.Internal`

import Swiftz

/// A bidirectional channel for information.
///
/// A `Proxy` is so named because it can represent many different kinds of information flows. There
Expand Down Expand Up @@ -76,6 +74,8 @@ public struct Proxy<UO, UI, DI, DO, FR> {
}
}

// MARK: Aliases

/// An effectful computation.
///
/// `Effect`s neither await nor yield.
Expand Down
6 changes: 2 additions & 4 deletions Aquifer/Simple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// roughly `Pipes`

import Swiftz

/// Pull the first value out of the given `Pipe`.
///
/// If the subsequent state of the `Pipe` is a single value or termination, the result is `.Left`
Expand Down Expand Up @@ -110,8 +108,8 @@ public func <-< <UO, UI, DI, DO, DDI, DDO, FR>(p : Proxy<DI, DO, DDI, DDO, FR>,

private func eachRepr<UO, UI, G : GeneratorType>(var gen : G) -> ProxyRepr<UO, UI, (), G.Element, ()> {
if let v = gen.next() {
return ProxyRepr.Respond(const(v)) { _ in eachRepr(gen) }
return ProxyRepr.Respond({ _ in v }) { _ in eachRepr(gen) }
} else {
return ProxyRepr.Pure(const(()))
return ProxyRepr.Pure({ _ in () })
}
}
2 changes: 0 additions & 2 deletions Aquifer/X.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// part of `Pipes.Internal`

import Swiftz

/// The (nominally) empty type, implemented as a semi-strictly self-recursive struct.
public struct X {
private let rec : () -> X
Expand Down
1 change: 0 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
github "typelift/Swiftz"
github "typelift/Focus"
1 change: 1 addition & 0 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github "typelift/SwiftCheck"
github "typelift/Operadics"
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "typelift/Focus" "v0.1.0"
github "typelift/SwiftCheck" "v0.3.1"
github "typelift/Swiftz" "v0.3.0"
github "typelift/Operadics" "0.1.4"
github "typelift/SwiftCheck" "v0.3.2"
1 change: 1 addition & 0 deletions Carthage/Checkouts/Operadics
Submodule Operadics added at c65e63
1 change: 0 additions & 1 deletion Carthage/Checkouts/Swiftz
Submodule Swiftz deleted from 210532