Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Swift2 #9

Closed
wants to merge 3 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cartfile.private
@@ -1,2 +1,2 @@
github "Quick/Nimble" ~> 0.4.0
github "Quick/Quick" ~> 0.3.0
github "Quick/Nimble" ~> 4.0
github "Quick/Quick" ~> 0.9.0
4 changes: 2 additions & 2 deletions Cartfile.resolved
@@ -1,2 +1,2 @@
github "Quick/Nimble" "v0.4.0"
github "Quick/Quick" "v0.3.0"
github "Quick/Nimble" "v4.0.1"
github "Quick/Quick" "v0.9.2"
13 changes: 12 additions & 1 deletion Monocle.xcodeproj/project.pbxproj
Expand Up @@ -309,7 +309,9 @@
544A7A8F1A8E1CD70056DE25 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastSwiftMigration = 0730;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = "Robert B枚hnke";
TargetAttributes = {
544A7A971A8E1CD70056DE25 = {
Expand Down Expand Up @@ -446,6 +448,7 @@
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -521,6 +524,7 @@
INFOPLIST_FILE = Monocle/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Monocle;
SKIP_INSTALL = YES;
};
Expand All @@ -538,6 +542,7 @@
INFOPLIST_FILE = Monocle/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Monocle;
SKIP_INSTALL = YES;
};
Expand All @@ -558,6 +563,7 @@
);
INFOPLIST_FILE = Specs/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -573,6 +579,7 @@
);
INFOPLIST_FILE = Specs/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -593,6 +600,7 @@
INFOPLIST_FILE = Monocle/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Monocle;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
Expand All @@ -613,6 +621,7 @@
INFOPLIST_FILE = Monocle/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Monocle;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
Expand All @@ -636,6 +645,7 @@
INFOPLIST_FILE = Specs/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
};
Expand All @@ -652,6 +662,7 @@
INFOPLIST_FILE = Specs/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
13 changes: 8 additions & 5 deletions Monocle.xcodeproj/xcshareddata/xcschemes/Monocle-Mac.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:Monocle.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
13 changes: 8 additions & 5 deletions Monocle.xcodeproj/xcshareddata/xcschemes/Monocle-iOS.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:Monocle.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
2 changes: 1 addition & 1 deletion Monocle/Info.plist
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
28 changes: 14 additions & 14 deletions Monocle/Lens.swift
Expand Up @@ -30,28 +30,28 @@ public func get<A, B>(lens: Lens<A, B>, a: A) -> B {
return lens.get(a)
}

public func get<A, B>(lens: Lens<A, B>)(a: A) -> B {
return lens.get(a)
public func get<A, B>(lens: Lens<A, B>) -> (a: A) -> B {
return lens.get
}

public func get<A, B>(lens: Lens<A, B>, a: A?) -> B? {
return map(a, lens.get)
return a.map(lens.get)
}

public func get<A, B>(lens: Lens<A, B>)(a: A?) -> B? {
return map(a, lens.get)
public func get<A, B>(lens: Lens<A, B>) -> (a: A?) -> B? {
return { $0.map(lens.get) }
}

public func set<A, B>(lens: Lens<A, B>, a: A, b: B) -> A {
return lens.set(a, b)
}

public func set<A, B>(lens: Lens<A, B>, a: A)(b: B) -> A {
return lens.set(a, b)
public func set<A, B>(lens: Lens<A, B>, a: A) -> (b: B) -> A {
return { lens.set(a, $0) }
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you remove this one?

Copy link
Author

Choose a reason for hiding this comment

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

oops. thanks for double checking. I'll update.

public func mod<A, B>(lens: Lens<A, B>, a: A, f: B -> B) -> A {
return set(lens, a, f(get(lens, a)))
return set(lens, a: a, b: f(get(lens, a: a)))
}

// MARK: - Compose
Expand All @@ -74,7 +74,7 @@ infix operator >>> {
}

public func >>> <A, B, C>(lhs: Lens<A, B>, rhs: Lens<B, C>) -> Lens<A, C> {
return compose(lhs, rhs)
return compose(lhs, right: rhs)
}

infix operator <<< {
Expand All @@ -83,18 +83,18 @@ infix operator <<< {
}

public func <<< <A, B, C>(lhs: Lens<B, C>, rhs: Lens<A, B>) -> Lens<A, C> {
return compose(rhs, lhs)
return compose(rhs, right: lhs)
}

// MARK: - Lift

public func lift<A, B>(lens: Lens<A, B>) -> Lens<[A], [B]> {
let get: [A] -> [B] = { xs in
return map(xs, lens.get)
return xs.map(lens.get)
}

let set: ([A], [B]) -> [A] = { xs, ys in
return map(zip(xs, ys), lens.set)
return zip(xs, ys).map(lens.set)
}

return Lens(get: get, set: set)
Expand All @@ -120,7 +120,7 @@ infix operator *** {
}

public func *** <A, B, C, D>(lhs: Lens<A, B>, rhs: Lens<C, D>) -> Lens<(A, C), (B, D)> {
return split(lhs, rhs)
return split(lhs, right: rhs)
}

// MARK: - Fanout
Expand All @@ -143,5 +143,5 @@ infix operator &&& {
}

public func &&& <A, B, C>(lhs: Lens<A, B>, rhs: Lens<A, C>) -> Lens<A, (B, C)> {
return fanout(lhs, rhs)
return fanout(lhs, right: rhs)
}
2 changes: 1 addition & 1 deletion Specs/Info.plist
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
26 changes: 13 additions & 13 deletions Specs/LensSpec.swift
Expand Up @@ -58,15 +58,15 @@ class LensSpec: QuickSpec {
let count = OuterLenses.count

it("should get values") {
expect(get(count, example)!).to(equal(2))
expect(get(count, a: example)!).to(equal(2))
}

it("should set values") {
expect(set(count, example, 4)).to(equal(Outer(count: 4)))
expect(set(count, a: example, b: 4)).to(equal(Outer(count: 4)))
}

it("should modify values") {
expect(mod(count, example, { $0 + 2 })).to(equal(Outer(count: 4)))
expect(mod(count, a: example, f: { $0 + 2 })).to(equal(Outer(count: 4)))
}
}

Expand All @@ -76,15 +76,15 @@ class LensSpec: QuickSpec {
let innerCount = OuterLenses.inner >>> InnerLenses.count

it("should get values") {
expect(get(innerCount, example)!).to(equal(2))
expect(get(innerCount, a: example)!).to(equal(2))
}

it("should set values") {
expect(set(innerCount, example, 4)).to(equal(Outer(count: 0, inner: Inner(count: 4))))
expect(set(innerCount, a: example, b: 4)).to(equal(Outer(count: 0, inner: Inner(count: 4))))
}

it("should modify values") {
expect(mod(innerCount, example, { $0 + 2 })).to(equal(Outer(count: 0, inner: Inner(count: 4))))
expect(mod(innerCount, a: example, f: { $0 + 2 })).to(equal(Outer(count: 0, inner: Inner(count: 4))))
}
}

Expand All @@ -100,13 +100,13 @@ class LensSpec: QuickSpec {
let lifted = lift(InnerLenses.count)

it("should get values") {
let result = get(lifted, inner)
let result = get(lifted, a: inner)

expect(result).to(equal([ 1, 2, 3, 4 ]))
}

it("should set values") {
let result = set(lifted, inner, [ 2, 4, 6, 8 ])
let result = set(lifted, a: inner, b: [ 2, 4, 6, 8 ])

expect(result).to(equal([
Inner(count: 2),
Expand All @@ -118,7 +118,7 @@ class LensSpec: QuickSpec {

it("should reduce the resulting array size accordingly") {
// Does this make sense?
let result = set(lifted, inner, [ 42 ])
let result = set(lifted, a: inner, b: [ 42 ])

expect(result).to(equal([
Inner(count: 42)
Expand All @@ -134,14 +134,14 @@ class LensSpec: QuickSpec {
let both = OuterLenses.count *** InnerLenses.count

it("should get values") {
let result = get(both, (outer, inner))
let result = get(both, a: (outer, inner))

expect(result.0).to(equal(2))
expect(result.1).to(equal(9))
}

it("should set values") {
let result = set(both, (outer, inner), (12, 34))
let result = set(both, a: (outer, inner), b: (12, 34))

expect(result.0.count).to(equal(12))
expect(result.0.inner.count).to(equal(4))
Expand All @@ -155,14 +155,14 @@ class LensSpec: QuickSpec {
let both = OuterLenses.count &&& (OuterLenses.inner >>> InnerLenses.count)

it("should get values") {
let result = get(both, example)
let result = get(both, a: example)

expect(result.0).to(equal(0))
expect(result.1).to(equal(2))
}

it("should set values") {
let result = set(both, example, (12, 34))
let result = set(both, a: example, b: (12, 34))

expect(result.count).to(equal(12))
expect(result.inner.count).to(equal(34))
Expand Down