Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into Swift-1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pNre committed Apr 12, 2015
2 parents ac0380d + 71e7fa8 commit 8beeb7f
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 97 deletions.
239 changes: 239 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
# Change Log

## [Unreleased](https://github.com/pNre/ExSwift/tree/HEAD)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.9...HEAD)

**Closed issues:**

- NSDate addUnit stuff not working in ios7 [\#97](https://github.com/pNre/ExSwift/issues/97)

- weak support [\#96](https://github.com/pNre/ExSwift/issues/96)

- @synchronized support [\#95](https://github.com/pNre/ExSwift/issues/95)

- string.toDouble\(\) should accept "1.23e4" [\#94](https://github.com/pNre/ExSwift/issues/94)

- Compile fix for Swift 1.2 [\#90](https://github.com/pNre/ExSwift/issues/90)

- Swift-1.2 branch causing Segmentation fault: 11 [\#81](https://github.com/pNre/ExSwift/issues/81)

- Support for Swift 1.2 [\#80](https://github.com/pNre/ExSwift/issues/80)

- Still breaks range literals [\#71](https://github.com/pNre/ExSwift/issues/71)

- flatMap [\#62](https://github.com/pNre/ExSwift/issues/62)

- Nil filter method on array [\#59](https://github.com/pNre/ExSwift/issues/59)

- don't use array extension function [\#54](https://github.com/pNre/ExSwift/issues/54)

- Documentation small issue [\#53](https://github.com/pNre/ExSwift/issues/53)

- Spare the TakeSequence and TakeWhileSequence structs [\#52](https://github.com/pNre/ExSwift/issues/52)

- No one is merging in changes [\#49](https://github.com/pNre/ExSwift/issues/49)

- Swift Compile Error on Xcode 6.1 [\#38](https://github.com/pNre/ExSwift/issues/38)

- ExSwift breaks range subscripting [\#32](https://github.com/pNre/ExSwift/issues/32)

- skipWhile [\#31](https://github.com/pNre/ExSwift/issues/31)

**Merged pull requests:**

- Enhance Carthage Support [\#103](https://github.com/pNre/ExSwift/pull/103) ([nebhale](https://github.com/nebhale))

- Remove Deprecation Warnings [\#102](https://github.com/pNre/ExSwift/pull/102) ([nebhale](https://github.com/nebhale))

- Fix compatibility issue NSDate add [\#101](https://github.com/pNre/ExSwift/pull/101) ([PGLongo](https://github.com/PGLongo))

- Ex.cached for 1-arg functions. [\#93](https://github.com/pNre/ExSwift/pull/93) ([hiltonc](https://github.com/hiltonc))

- fixed for Xcode Version 6.3 beta 3 [\#89](https://github.com/pNre/ExSwift/pull/89) ([katopz](https://github.com/katopz))

- fix compiler error 'missing argument \#2' [\#88](https://github.com/pNre/ExSwift/pull/88) ([sebbean](https://github.com/sebbean))

- Format Number [\#86](https://github.com/pNre/ExSwift/pull/86) ([PGLongo](https://github.com/PGLongo))

- Fix compiler errors in second Xcode 6.3 beta \(6D532l\). [\#84](https://github.com/pNre/ExSwift/pull/84) ([JakobR](https://github.com/JakobR))

- Add Lisp's find method to Arrays. [\#83](https://github.com/pNre/ExSwift/pull/83) ([nickmshelley](https://github.com/nickmshelley))

- Add Bool extension [\#79](https://github.com/pNre/ExSwift/pull/79) ([davidman](https://github.com/davidman))

- Swift 1.2 \(Xcode 6.3\) support [\#78](https://github.com/pNre/ExSwift/pull/78) ([markusl](https://github.com/markusl))

- Made Framework and Unit Test iOS / OS X universal [\#76](https://github.com/pNre/ExSwift/pull/76) ([colemancda](https://github.com/colemancda))

- added method and tests [\#73](https://github.com/pNre/ExSwift/pull/73) ([michaeleisel](https://github.com/michaeleisel))

- added methods and tests [\#72](https://github.com/pNre/ExSwift/pull/72) ([michaeleisel](https://github.com/michaeleisel))

- added method and tests [\#70](https://github.com/pNre/ExSwift/pull/70) ([michaeleisel](https://github.com/michaeleisel))

- added method, tests, and whitespace changes [\#69](https://github.com/pNre/ExSwift/pull/69) ([michaeleisel](https://github.com/michaeleisel))

- Round to nearest [\#68](https://github.com/pNre/ExSwift/pull/68) ([michaeleisel](https://github.com/michaeleisel))

- added arithmetic methods [\#67](https://github.com/pNre/ExSwift/pull/67) ([michaeleisel](https://github.com/michaeleisel))

- added strideable methods [\#66](https://github.com/pNre/ExSwift/pull/66) ([michaeleisel](https://github.com/michaeleisel))

- removed unnecessary methods [\#65](https://github.com/pNre/ExSwift/pull/65) ([michaeleisel](https://github.com/michaeleisel))

- completely redid permutation generating [\#64](https://github.com/pNre/ExSwift/pull/64) ([michaeleisel](https://github.com/michaeleisel))

- Add shared schemes for installation by Carthage. [\#63](https://github.com/pNre/ExSwift/pull/63) ([yoichitgy](https://github.com/yoichitgy))

- Add getter and comparison to NSDate [\#61](https://github.com/pNre/ExSwift/pull/61) ([PGLongo](https://github.com/PGLongo))

- mapAccum for Array [\#60](https://github.com/pNre/ExSwift/pull/60) ([phatmann](https://github.com/phatmann))

- Added to\* methods to readme docs. [\#58](https://github.com/pNre/ExSwift/pull/58) ([mikeckennedy](https://github.com/mikeckennedy))

- Trimmed methods fail on string that contains only whitespace [\#57](https://github.com/pNre/ExSwift/pull/57) ([pizthewiz](https://github.com/pizthewiz))

- Add toNumeric \(e.g. toDouble\) conversions to string extensions [\#56](https://github.com/pNre/ExSwift/pull/56) ([mikeckennedy](https://github.com/mikeckennedy))

- Added overloaded ltrimmed and rtrimmed methods [\#55](https://github.com/pNre/ExSwift/pull/55) ([hhoangnl](https://github.com/hhoangnl))

- Update Dictionary.swift [\#51](https://github.com/pNre/ExSwift/pull/51) ([davidman](https://github.com/davidman))

- Added Charater extension [\#50](https://github.com/pNre/ExSwift/pull/50) ([cennydavidsson](https://github.com/cennydavidsson))

- Repeated permutations [\#48](https://github.com/pNre/ExSwift/pull/48) ([michaeleisel](https://github.com/michaeleisel))

- Added NSDate methods [\#47](https://github.com/pNre/ExSwift/pull/47) ([PGLongo](https://github.com/PGLongo))

- Repeated combinations [\#46](https://github.com/pNre/ExSwift/pull/46) ([michaeleisel](https://github.com/michaeleisel))

- Fill [\#45](https://github.com/pNre/ExSwift/pull/45) ([michaeleisel](https://github.com/michaeleisel))

- Transpose [\#44](https://github.com/pNre/ExSwift/pull/44) ([michaeleisel](https://github.com/michaeleisel))

- Permutations [\#43](https://github.com/pNre/ExSwift/pull/43) ([michaeleisel](https://github.com/michaeleisel))

- added combinations method [\#42](https://github.com/pNre/ExSwift/pull/42) ([michaeleisel](https://github.com/michaeleisel))

- Unique by method [\#41](https://github.com/pNre/ExSwift/pull/41) ([michaeleisel](https://github.com/michaeleisel))

- Added UIColor extension [\#39](https://github.com/pNre/ExSwift/pull/39) ([PGLongo](https://github.com/PGLongo))

- Added minBy and maxBy methods [\#37](https://github.com/pNre/ExSwift/pull/37) ([michaeleisel](https://github.com/michaeleisel))

- Add installation instruction [\#35](https://github.com/pNre/ExSwift/pull/35) ([kostiakoval](https://github.com/kostiakoval))

- the script can generation a Framework of StaticLibrary [\#30](https://github.com/pNre/ExSwift/pull/30) ([zhfish](https://github.com/zhfish))

## [0.1.9](https://github.com/pNre/ExSwift/tree/0.1.9) (2014-08-20)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.8...0.1.9)

**Merged pull requests:**

- Added count methods [\#27](https://github.com/pNre/ExSwift/pull/27) ([jmnavarro](https://github.com/jmnavarro))

## [0.1.8](https://github.com/pNre/ExSwift/tree/0.1.8) (2014-08-05)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.7...0.1.8)

**Closed issues:**

- ExSwift broken in beta 5 [\#26](https://github.com/pNre/ExSwift/issues/26)

- Single index string subscripting results in compiler error [\#25](https://github.com/pNre/ExSwift/issues/25)

- Array.indexOf not working with \[UInt\] [\#21](https://github.com/pNre/ExSwift/issues/21)

**Merged pull requests:**

- Changes =~ to take regular expression. [\#22](https://github.com/pNre/ExSwift/pull/22) ([nomothetis](https://github.com/nomothetis))

## [0.1.7](https://github.com/pNre/ExSwift/tree/0.1.7) (2014-07-25)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.6...0.1.7)

**Closed issues:**

- Breaks in Xcode6-Beta4 [\#19](https://github.com/pNre/ExSwift/issues/19)

**Merged pull requests:**

- Added access modifiers [\#20](https://github.com/pNre/ExSwift/pull/20) ([vmartinelli](https://github.com/vmartinelli))

## [0.1.6](https://github.com/pNre/ExSwift/tree/0.1.6) (2014-07-22)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.5...0.1.6)

## [0.1.5](https://github.com/pNre/ExSwift/tree/0.1.5) (2014-07-19)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.4...0.1.5)

**Closed issues:**

- Support for Double / Integer [\#18](https://github.com/pNre/ExSwift/issues/18)

- Help, got so many compile errors [\#17](https://github.com/pNre/ExSwift/issues/17)

## [0.1.4](https://github.com/pNre/ExSwift/tree/0.1.4) (2014-07-07)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.3...0.1.4)

**Merged pull requests:**

- used shuffle\(\) to shuffle in shuffled\(\) [\#16](https://github.com/pNre/ExSwift/pull/16) ([natecook1000](https://github.com/natecook1000))

## [0.1.3](https://github.com/pNre/ExSwift/tree/0.1.3) (2014-07-03)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.2...0.1.3)

**Merged pull requests:**

- Sequence ops [\#15](https://github.com/pNre/ExSwift/pull/15) ([ColinEberhardt](https://github.com/ColinEberhardt))

- Added a toDictionary method [\#13](https://github.com/pNre/ExSwift/pull/13) ([ColinEberhardt](https://github.com/ColinEberhardt))

- Added a sortBy method [\#12](https://github.com/pNre/ExSwift/pull/12) ([ColinEberhardt](https://github.com/ColinEberhardt))

- Define iOS module with the same name as OS X, cleanup duplicate files [\#11](https://github.com/pNre/ExSwift/pull/11) ([garnett](https://github.com/garnett))

- Simplify partition tests [\#10](https://github.com/pNre/ExSwift/pull/10) ([zolrath](https://github.com/zolrath))

## [0.1.2](https://github.com/pNre/ExSwift/tree/0.1.2) (2014-06-18)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.1...0.1.2)

**Fixed bugs:**

- Compile error: Access String array by subscript [\#6](https://github.com/pNre/ExSwift/issues/6)

**Closed issues:**

- Result of indexOf, lastIndexOf should be an optional [\#8](https://github.com/pNre/ExSwift/issues/8)

**Merged pull requests:**

- Add .gitignore, add iOS Framework + tests target [\#7](https://github.com/pNre/ExSwift/pull/7) ([garnett](https://github.com/garnett))

- return Int? in indexOf, lastIndexOf [\#9](https://github.com/pNre/ExSwift/pull/9) ([garnett](https://github.com/garnett))

- Add partition, partitionAll, and partitionBy [\#5](https://github.com/pNre/ExSwift/pull/5) ([zolrath](https://github.com/zolrath))

- Add takeWhile and skipWhile to Array [\#4](https://github.com/pNre/ExSwift/pull/4) ([zolrath](https://github.com/zolrath))

## [0.1.1](https://github.com/pNre/ExSwift/tree/0.1.1) (2014-06-11)

[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.0...0.1.1)

**Merged pull requests:**

- Use if let syntax for Dictionary {group, count}by [\#3](https://github.com/pNre/ExSwift/pull/3) ([zolrath](https://github.com/zolrath))

- Use if let syntax for groupBy and countBy [\#2](https://github.com/pNre/ExSwift/pull/2) ([zolrath](https://github.com/zolrath))

## [0.1.0](https://github.com/pNre/ExSwift/tree/0.1.0) (2014-06-10)



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
11 changes: 11 additions & 0 deletions ExSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
CC633BA61A37142900341557 /* CharacterExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC633BA51A37142900341557 /* CharacterExtensionsTests.swift */; };
CC633BA71A37144E00341557 /* Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC8C1D701A365CA6003D386E /* Character.swift */; };
CC8C1D711A365CA6003D386E /* Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC8C1D701A365CA6003D386E /* Character.swift */; };
3C0AB97E195C7FC20009BDA0 /* ExSwiftSequenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0AB97C195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift */; };
6CB1F15F1A8AB867002EA767 /* Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F15E1A8AB867002EA767 /* Bool.swift */; };
6CB1F1611A8AB8D3002EA767 /* ExSwiftBoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F1601A8AB8D3002EA767 /* ExSwiftBoolTests.swift */; };
6CB1F1621A8AB979002EA767 /* ExSwiftBoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F1601A8AB8D3002EA767 /* ExSwiftBoolTests.swift */; };
6CB1F1631A8ABA1A002EA767 /* Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F15E1A8AB867002EA767 /* Bool.swift */; };
6CB1F1641A8ABA1A002EA767 /* Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F15E1A8AB867002EA767 /* Bool.swift */; };
6CB1F1661A8ABA1C002EA767 /* Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F15E1A8AB867002EA767 /* Bool.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -135,6 +142,7 @@
CC633BA51A37142900341557 /* CharacterExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterExtensionsTests.swift; sourceTree = "<group>"; };
CC8C1D701A365CA6003D386E /* Character.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Character.swift; sourceTree = "<group>"; };
FA8EE3398AF8D20E3CE7A698 /* Pods-ExSwiftTests-OSX.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExSwiftTests-OSX.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ExSwiftTests-OSX/Pods-ExSwiftTests-OSX.debug.xcconfig"; sourceTree = "<group>"; };
6CB1F15E1A8AB867002EA767 /* Bool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bool.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -210,6 +218,7 @@
1E11AFB11943225B006BCE48 /* String.swift */,
1EC241FB1946E91B0047109A /* NSArray.swift */,
12168FC91A22852300ED4105 /* NSDate.swift */,
6CB1F15E1A8AB867002EA767 /* Bool.swift */,
1E11AF891943222D006BCE48 /* ExSwift.h */,
1E11AF871943222D006BCE48 /* Supporting Files */,
);
Expand Down Expand Up @@ -550,6 +559,7 @@
3C0AB978195C7FAF0009BDA0 /* Sequence.swift in Sources */,
1E11AFB21943225B006BCE48 /* Array.swift in Sources */,
1ED536841943863100BDA94E /* ExSwift.swift in Sources */,
6CB1F15F1A8AB867002EA767 /* Bool.swift in Sources */,
1E11AFB41943225B006BCE48 /* Dictionary.swift in Sources */,
1E11AFB61943225B006BCE48 /* Float.swift in Sources */,
1E11AFB81943225B006BCE48 /* Int.swift in Sources */,
Expand Down Expand Up @@ -579,6 +589,7 @@
2EB34F0C195473AC00A8D2AF /* NSArray.swift in Sources */,
CC633BA71A37144E00341557 /* Character.swift in Sources */,
2EB34F05195473AC00A8D2AF /* ExSwift.swift in Sources */,
6CB1F1631A8ABA1A002EA767 /* Bool.swift in Sources */,
2EB34F08195473AC00A8D2AF /* Float.swift in Sources */,
12168FCD1A2285A900ED4105 /* NSDateExtensionsTests.swift in Sources */,
1E11AFAB19432236006BCE48 /* StringExtensionsTests.swift in Sources */,
Expand Down
26 changes: 25 additions & 1 deletion ExSwift/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ internal extension Array {
@availability(*, unavailable, message="use the 'last' property instead") func last () -> Element? {
return last
}

/**
First occurrence of item, if found.

:param: item The item to search for
:returns: Matched item or nil
*/
func find <U: Equatable> (item: U) -> T? {
if let index = indexOf(item) {
return self[index]
}

return nil
}

/**
First item that meets the condition.

:param: condition A function which returns a boolean if an element satisfies a given condition or not.
:returns: First matched item or nil
*/
func find (condition: Element -> Bool) -> Element? {
return takeFirst(condition)
}

/**
Index of the first occurrence of item, if found.
Expand All @@ -133,7 +157,7 @@ internal extension Array {
*/
func indexOf <U: Equatable> (item: U) -> Int? {
if item is Element {
return find(unsafeBitCast(self, [U].self), item)
return Swift.find(unsafeBitCast(self, [U].self), item)
}

return nil
Expand Down
18 changes: 18 additions & 0 deletions ExSwift/Bool.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Bool.swift
// ExSwift
//
// Created by Hernandez Alvarez, David on 2/10/15.
// Copyright (c) 2015 pNre. All rights reserved.
//

import Foundation

extension Bool {

mutating func toggle() -> Bool {
self = !self
return self
}

}
31 changes: 26 additions & 5 deletions ExSwift/ExSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@ public class ExSwift {
}
}

/**
Creates a wrapper for function that caches the result of function's invocations.

:param: function Function with one parameter to cache
:returns: Wrapper function
*/
public class func cached <P: Hashable, R> (function: P -> R) -> (P -> R) {
var cache = [P:R]()

return { (param: P) -> R in
let key = param

if let cachedValue = cache[key] {
return cachedValue
} else {
let value = function(param)
cache[key] = value
return value
}
}
}

/**
Creates a wrapper for function that caches the result of function's invocations.

Expand All @@ -154,19 +176,18 @@ public class ExSwift {
var cache = [P:R]()

return { (params: P...) -> R in

let adaptedFunction = unsafeBitCast(function, Function.self)
let adaptedHash = unsafeBitCast(hash, Hash.self)

let key = adaptedHash(params)

if let cachedValue = cache[key] {
return cachedValue
} else {
let value = adaptedFunction(params)
cache[key] = value
return value
}

cache[key] = adaptedFunction(params)

return cache[key]!
}
}

Expand Down
Loading

0 comments on commit 8beeb7f

Please sign in to comment.