Skip to content

Commit

Permalink
Merge remote-tracking branch 'khanlou/master' into cocoapods
Browse files Browse the repository at this point in the history
# Conflicts:
#	Promise.xcodeproj/project.pbxproj
#	README.md
  • Loading branch information
mergesort committed Sep 30, 2017
2 parents e1bee35 + d214c69 commit 99a0b1b
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//: [Previous](@previous)

/*:

# Zip Functions Generator

This page generates `zip` functions for 3-*N* parameters. They all build on the
two parameter variant, with `zip` for *N* parameters always delegating work
to one with *N*-1 parameters.

*/

import Foundation

func types(_ n: Int) -> String {
return (1...n).map { "T\($0)" }.joined(separator: ", ")
}


func createZip(_ n: Int) -> String {
var output: String = "/// Zips \(n) promises of different types into a single Promise whose\n"
output.append("/// type is a tuple of \(n) elements.\n")
output.append("public static func zip<")
output.append(types(n))
output.append(">(")
output.append((1...n-1).map { "_ p\($0): Promise<T\($0)>, " }.joined())
output.append("_ last: Promise<T\(n)>) -> Promise<(\(types(n)))> {\n")

output.append("return Promise<(\(types(n)))>(work: { (fulfill: @escaping ((\(types(n)))) -> Void, reject: @escaping (Error) -> Void) in\n")

output.append("let zipped: Promise<(\(types(n-1)))> = zip(")
output.append((1...n-1).map { "p\($0)" }.joined(separator: ", "))
output.append(")\n\n")

output.append("func resolver() -> Void {\n")
output.append("if let zippedValue = zipped.value, let lastValue = last.value {\n")
output.append("fulfill((")
output.append((0...n-2).map { "zippedValue.\($0), " }.joined())
output.append("lastValue))\n}\n}\n")

output.append("zipped.then({ _ in resolver() }, reject)\n")
output.append("last.then({ _ in resolver() }, reject)\n")

output.append("})\n}")

return output
}

func createZips(_ n: Int) -> String {
return (3...n).map(createZip).joined(separator: "\n\n")
}

print(createZips(6))


//: [Next](@next)
1 change: 1 addition & 0 deletions Promise.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<pages>
<page name='Basic Usage'/>
<page name='Common Patterns'/>
<page name='Zip Functions Generator'/>
</pages>
</playground>
108 changes: 106 additions & 2 deletions Promise.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1A2A8CFA1D5D717D00421E3E /* PromiseAlwaysTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2A8CF91D5D717D00421E3E /* PromiseAlwaysTests.swift */; };
1A2A8CFC1D5D743100421E3E /* PromiseRecoverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2A8CFB1D5D743100421E3E /* PromiseRecoverTests.swift */; };
1A2A8CFE1D5D764600421E3E /* PromiseRetryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2A8CFD1D5D764600421E3E /* PromiseRetryTests.swift */; };
1A42330C1F6ECC250045B066 /* PromiseKickoffTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A42330B1F6ECC250045B066 /* PromiseKickoffTests.swift */; };
1A7CC22F1DF4D37400929E7C /* PromiseEnsureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A7CC22E1DF4D37400929E7C /* PromiseEnsureTests.swift */; };
1AF54F3B1D67D60000557CCB /* PromiseZipTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AF54F3A1D67D60000557CCB /* PromiseZipTests.swift */; };
1AFA1FA01D8A0C9500E4F76E /* PromiseThrowsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AFA1F9F1D8A0C9500E4F76E /* PromiseThrowsTests.swift */; };
Expand Down Expand Up @@ -43,6 +44,7 @@
1A2A8CF91D5D717D00421E3E /* PromiseAlwaysTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseAlwaysTests.swift; sourceTree = "<group>"; };
1A2A8CFB1D5D743100421E3E /* PromiseRecoverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseRecoverTests.swift; sourceTree = "<group>"; };
1A2A8CFD1D5D764600421E3E /* PromiseRetryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseRetryTests.swift; sourceTree = "<group>"; };
1A42330B1F6ECC250045B066 /* PromiseKickoffTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseKickoffTests.swift; sourceTree = "<group>"; };
1A7CC22E1DF4D37400929E7C /* PromiseEnsureTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseEnsureTests.swift; sourceTree = "<group>"; };
1AF54F3A1D67D60000557CCB /* PromiseZipTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseZipTests.swift; sourceTree = "<group>"; };
1AFA1F9F1D8A0C9500E4F76E /* PromiseThrowsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseThrowsTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,6 +78,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
52F3C1C01ECE503D0028CA53 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand All @@ -94,6 +103,7 @@
children = (
3454F9CE1D4FACD000985BBF /* Promise.framework */,
3454F9D81D4FACD000985BBF /* PromiseTests.xctest */,
52F3C1C71ECE503D0028CA53 /* Promise.framework */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -126,6 +136,7 @@
1A7CC22E1DF4D37400929E7C /* PromiseEnsureTests.swift */,
72B61D3B1E00E5830008E829 /* Wrench.swift */,
1A0073671E2865CC00EB319A /* ExecutionContextTests.swift */,
1A42330B1F6ECC250045B066 /* PromiseKickoffTests.swift */,
);
path = PromiseTests;
sourceTree = "<group>";
Expand All @@ -141,6 +152,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
52F3C1C11ECE503D0028CA53 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
52F3C1C21ECE503D0028CA53 /* Promise.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -180,6 +199,24 @@
productReference = 3454F9D81D4FACD000985BBF /* PromiseTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
52F3C1BC1ECE503D0028CA53 /* Promise Mac */ = {
isa = PBXNativeTarget;
buildConfigurationList = 52F3C1C41ECE503D0028CA53 /* Build configuration list for PBXNativeTarget "Promise Mac" */;
buildPhases = (
52F3C1BD1ECE503D0028CA53 /* Sources */,
52F3C1C01ECE503D0028CA53 /* Frameworks */,
52F3C1C11ECE503D0028CA53 /* Headers */,
52F3C1C31ECE503D0028CA53 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = "Promise Mac";
productName = Promise;
productReference = 52F3C1C71ECE503D0028CA53 /* Promise.framework */;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
Expand Down Expand Up @@ -212,6 +249,7 @@
projectRoot = "";
targets = (
3454F9CD1D4FACD000985BBF /* Promise */,
52F3C1BC1ECE503D0028CA53 /* Promise Mac */,
3454F9D71D4FACD000985BBF /* PromiseTests */,
);
};
Expand All @@ -232,6 +270,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
52F3C1C31ECE503D0028CA53 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -259,11 +304,21 @@
1AFF80FA1D5166C000C55D5A /* delay.swift in Sources */,
1AFF80FC1D51676700C55D5A /* PromiseAllTests.swift in Sources */,
3454F9DE1D4FACD000985BBF /* PromiseTests.swift in Sources */,
1A42330C1F6ECC250045B066 /* PromiseKickoffTests.swift in Sources */,
1A2A8CF61D5D36C500421E3E /* PromiseDelayTests.swift in Sources */,
1A7CC22F1DF4D37400929E7C /* PromiseEnsureTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
52F3C1BD1ECE503D0028CA53 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
52F3C1BE1ECE503D0028CA53 /* Promise+Extras.swift in Sources */,
52F3C1BF1ECE503D0028CA53 /* Promise.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
Expand Down Expand Up @@ -315,7 +370,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -360,7 +415,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -433,6 +488,46 @@
};
name = Release;
};
52F3C1C51ECE503D0028CA53 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Promise/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.khanlou.Promise;
PRODUCT_NAME = Promise;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
52F3C1C61ECE503D0028CA53 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Promise/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.khanlou.Promise;
PRODUCT_NAME = Promise;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand Down Expand Up @@ -463,6 +558,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
52F3C1C41ECE503D0028CA53 /* Build configuration list for PBXNativeTarget "Promise Mac" */ = {
isa = XCConfigurationList;
buildConfigurations = (
52F3C1C51ECE503D0028CA53 /* Debug */,
52F3C1C61ECE503D0028CA53 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 3454F9C51D4FACD000985BBF /* Project object */;
Expand Down
82 changes: 82 additions & 0 deletions Promise.xcodeproj/xcshareddata/xcschemes/Promise macOS.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "52F3C1BC1ECE503D0028CA53"
BuildableName = "Promise Mac"
BlueprintName = "Promise Mac"
ReferencedContainer = "container:Promise.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "52F3C1BC1ECE503D0028CA53"
BuildableName = "Promise Mac"
BlueprintName = "Promise Mac"
ReferencedContainer = "container:Promise.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "52F3C1BC1ECE503D0028CA53"
BuildableName = "Promise Mac"
BlueprintName = "Promise Mac"
ReferencedContainer = "container:Promise.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
8 changes: 7 additions & 1 deletion Promise/Promise.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
//
//

#import <UIKit/UIKit.h>
#include <TargetConditionals.h>

#if TARGET_OS_IPHONE
@import UIKit;
#else
@import AppKit;
#endif

//! Project version number for Promise.
FOUNDATION_EXPORT double PromiseVersionNumber;
Expand Down
Loading

0 comments on commit 99a0b1b

Please sign in to comment.