Skip to content
Open
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
10 changes: 10 additions & 0 deletions Fission.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
B92E5B111DEA3D04008F5F32 /* PrcendenceGroups.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92E5B101DEA3D04008F5F32 /* PrcendenceGroups.swift */; };
B98C47AF1C21248B003F157C /* CollectionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B98C47A71C21248B003F157C /* CollectionType.swift */; };
B98C47B01C21248B003F157C /* CollectionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B98C47A71C21248B003F157C /* CollectionType.swift */; };
B98C47B11C21248B003F157C /* Curry.swift in Sources */ = {isa = PBXBuildFile; fileRef = B98C47A81C21248B003F157C /* Curry.swift */; };
Expand Down Expand Up @@ -40,6 +41,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
B92E5B101DEA3D04008F5F32 /* PrcendenceGroups.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrcendenceGroups.swift; sourceTree = "<group>"; };
B93D3C4B1C1FD5F200557F6F /* Fission.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Fission.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B93D3C7E1C20F42D00557F6F /* Fission.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Fission.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B98C47A71C21248B003F157C /* CollectionType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionType.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -112,6 +114,7 @@
B98C47AA1C21248B003F157C /* FunctionComposition.swift */,
B98C47AB1C21248B003F157C /* Mutation.swift */,
B98C47AC1C21248B003F157C /* Operators.swift */,
B92E5B101DEA3D04008F5F32 /* PrcendenceGroups.swift */,
B98C47AD1C21248B003F157C /* Optional.swift */,
B98C47AE1C21248B003F157C /* SequenceType.swift */,
);
Expand Down Expand Up @@ -224,12 +227,14 @@
TargetAttributes = {
B93D3C4A1C1FD5F200557F6F = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0810;
};
B93D3C7D1C20F42D00557F6F = {
CreatedOnToolsVersion = 7.2;
};
B9E527781C211B8E00011F20 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0810;
};
};
};
Expand Down Expand Up @@ -283,6 +288,7 @@
files = (
B98C47BD1C21248B003F157C /* SequenceType.swift in Sources */,
B98C47B31C21248B003F157C /* FunctionApplication.swift in Sources */,
B92E5B111DEA3D04008F5F32 /* PrcendenceGroups.swift in Sources */,
B98C47AF1C21248B003F157C /* CollectionType.swift in Sources */,
B98C47B51C21248B003F157C /* FunctionComposition.swift in Sources */,
B98C47BB1C21248B003F157C /* Optional.swift in Sources */,
Expand Down Expand Up @@ -429,6 +435,7 @@
PRODUCT_NAME = Fission;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -448,6 +455,7 @@
PRODUCT_BUNDLE_IDENTIFIER = pear.Fission;
PRODUCT_NAME = Fission;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -500,6 +508,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = pear.FissionMacTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -511,6 +520,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = pear.FissionMacTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
8 changes: 4 additions & 4 deletions Fission/CollectionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
// Copyright © 2015 Kenneth Ackerson. All rights reserved.
//

public extension CollectionType {
public func apply<T> (transforms: [Self.Generator.Element -> T]) -> [T] {
public extension Collection {
public func apply<T> (_ transforms: [(Self.Iterator.Element) -> T]) -> [T] {
return transforms.flatMap { return self.map($0) }
}
}

public func <*> <T, U: CollectionType> (transforms: [U.Generator.Element -> T], collection: U) -> [T] {
public func <*> <T, U: Collection> (transforms: [(U.Iterator.Element) -> T], collection: U) -> [T] {
return collection.apply <| transforms
}

public func <^> <T, U, C: CollectionType where C.Generator.Element == T> (@noescape transform: T throws -> U, collection: C) rethrows -> [U] {
public func <^> <T, U, C: Collection> (transform: (T) throws -> U, collection: C) rethrows -> [U] where C.Iterator.Element == T {
return try collection.map(transform)
}
4 changes: 2 additions & 2 deletions Fission/Curry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Transforms a function with two arguments into two functions with one argument ea

- returns: A curried version of the provided function.
*/
public func curry<T, U, V> (f: (T, U) -> V) -> T -> U -> V {
public func curry<T, U, V> (_ f: @escaping (T, U) -> V) -> (T) -> (U) -> V {
return { x in
return {
return f <| (x, $0)
Expand All @@ -28,7 +28,7 @@ public func curry<T, U, V> (f: (T, U) -> V) -> T -> U -> V {

- returns: An uncurried version of the provided function.
*/
public func uncurry<T, U, V> (f: T -> U -> V) -> (T, U) -> V {
public func uncurry<T, U, V> (_ f: @escaping (T) -> (U) -> V) -> (T, U) -> V {
return {
return f <| $0 <| $1
}
Expand Down
4 changes: 2 additions & 2 deletions Fission/FunctionApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Copyright © 2015 Kenneth Ackerson. All rights reserved.
//

public func |> <T, U> (lhs: T, @noescape transform: T -> U) -> U {
public func |> <T, U> (lhs: T, transform: (T) -> U) -> U {
return transform(lhs)
}

public func <| <T, U> (@noescape transform: T -> U, rhs: T) -> U {
public func <| <T, U> (transform: (T) -> U, rhs: T) -> U {
return transform(rhs)
}
8 changes: 4 additions & 4 deletions Fission/FunctionComposition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
//

/**
Function composostion operator.
Function composition operator.

- parameter lhs: The function on the left hand side of this operator. First function to be composed.
- parameter rhs: The function on the right hand side of this operator. Second function to be composed.

- returns: A function that transforms the first argument of the first function into the return value of the second function.
*/
public func >>> <T, U, V>(lhs: T -> U, rhs: U -> V) -> T -> V {
public func >>> <T, U, V>(lhs: @escaping (T) -> U, rhs: @escaping (U) -> V) -> (T) -> V {
return {
return $0 |> lhs |> rhs
}
}

/**
Function composostion operator.
Function composition operator.

- parameter lhs: The function on the left hand side of this operator. First function to be composed.
- parameter rhs: The function on the right hand side of this operator. Second function to be composed.

- returns: A function that transforms the first argument of the first function into the return value of the second function.
*/
public func <<< <T, U, V>(lhs: U -> V, rhs: T -> U) -> T -> V {
public func <<< <T, U, V>(lhs: @escaping (U) -> V, rhs: @escaping (T) -> U) -> (T) -> V {
return {
return $0 |> rhs |> lhs
}
Expand Down
4 changes: 2 additions & 2 deletions Fission/Mutation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

/// Based on https://twitter.com/jckarter/status/675445367542968320
public func apply<T, U> (transform: inout T -> U -> ()) -> T -> U -> T {
public func apply<T, U> (_ transform: @escaping (inout T) -> (U) -> ()) -> (T) -> (U) -> T {
return { a in
{ b in
var mutable = a
Expand All @@ -30,6 +30,6 @@ public func apply<T, U> (transform: inout T -> U -> ()) -> T -> U -> T {

- returns: A function that returns a function that can tranform `U` to `T`.
*/
public func <-><T, U> (f: inout T -> U -> (), t: T) -> U -> T {
public func <-><T, U> (f: @escaping (inout T) -> (U) -> (), t: T) -> (U) -> T {
return t |> (apply <| f)
}
61 changes: 17 additions & 44 deletions Fission/Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,20 @@
// Copyright © 2015 Kenneth Ackerson. All rights reserved.
//

infix operator <^> {
associativity left
precedence 130
}

infix operator <-> {
associativity right
precedence 170
}

infix operator <*> {
associativity left
precedence 130
}

infix operator -<< {
associativity right
precedence 110
}

infix operator >>- {
associativity left
precedence 110
}

infix operator |> {
associativity left
precedence 95
}

infix operator <| {
associativity left
precedence 95
}

infix operator >>> {
associativity right
precedence 175
}

infix operator <<< {
associativity right
precedence 175
}
infix operator <^> : LeftDefaultMonadicFunctions

infix operator <-> : RightDefaultMonadicFunctions

infix operator <*> : LeftDefaultMonadicFunctions

infix operator -<< : RightDefaultMonadicFunctions

infix operator >>- : LeftDefaultMonadicFunctions

infix operator |> : ApplicationLeft

infix operator <| : ApplicationRight

infix operator >>> : RightDefaultMonadicFunctions

infix operator <<< : RightDefaultMonadicFunctions
10 changes: 5 additions & 5 deletions Fission/Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

- returns: `nil` if `self` is nil, `f(self!)` otherwise.
*/
public func >>- <T, U> (optional: T?, @noescape transform: T throws -> U?) rethrows -> U? {
public func >>- <T, U> (optional: T?, transform: (T) throws -> U?) rethrows -> U? {
return try optional.flatMap(transform)
}

Expand All @@ -30,7 +30,7 @@ public func >>- <T, U> (optional: T?, @noescape transform: T throws -> U?) rethr

- returns: `nil` if `self` is nil, `f(self!)` otherwise.
*/
public func -<< <T, U> (@noescape transform: T throws -> U?, optional: T?) rethrows -> U? {
public func -<< <T, U> (transform: (T) throws -> U?, optional: T?) rethrows -> U? {
return try optional.flatMap(transform)
}

Expand All @@ -44,7 +44,7 @@ public func -<< <T, U> (@noescape transform: T throws -> U?, optional: T?) rethr

- returns: `nil` if `self == nil`. Otherwise, returns `f(self!)`.
*/
public func <^> <T, U> (@noescape transform: T throws -> U, optional: T?) rethrows -> U? {
public func <^> <T, U> (transform: (T) throws -> U, optional: T?) rethrows -> U? {
return try optional.map(transform)
}

Expand All @@ -57,7 +57,7 @@ public extension Optional {

- returns: If `self` or the transform function are `nil` this returns `nil`. Returns an optional type `T`.
*/
public func apply<T> (transform: (Wrapped -> T)?) -> T? {
public func apply<T> (_ transform: ((Wrapped) -> T)?) -> T? {
return transform.flatMap {
self.map($0)
}
Expand All @@ -72,6 +72,6 @@ public extension Optional {

- returns: If `self` or the transform function are `nil` this returns `nil`. Returns an optional type `U`.
*/
public func <*><T, U> (transform: (T -> U)?, optional: T?) -> U? {
public func <*><T, U> (transform: ((T) -> U)?, optional: T?) -> U? {
return optional.apply <| transform
}
29 changes: 29 additions & 0 deletions Fission/PrcendenceGroups.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// PrcendenceGroups.swift
// Fission
//
// Created by Kenneth Parker Ackerson on 11/26/16.
// Copyright © 2016 Kenneth Ackerson. All rights reserved.
//

precedencegroup ApplicationRight {
associativity: left
higherThan: AssignmentPrecedence
}

precedencegroup ApplicationLeft {
associativity: left
higherThan: AssignmentPrecedence
}

precedencegroup LeftDefaultMonadicFunctions {
associativity: left
higherThan: AssignmentPrecedence
lowerThan: LogicalDisjunctionPrecedence
}

precedencegroup RightDefaultMonadicFunctions {
associativity: left
higherThan: AssignmentPrecedence
lowerThan: LogicalDisjunctionPrecedence
}
6 changes: 3 additions & 3 deletions Fission/SequenceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2015 Kenneth Ackerson. All rights reserved.
//

public func >>- <T, S: SequenceType, U: SequenceType where U.Generator.Element == T> (sequence: U, transform: T throws -> S) rethrows -> [S.Generator.Element] {
public func >>- <T, S: Sequence, U: Sequence> (sequence: U, transform: (T) throws -> S) rethrows -> [S.Iterator.Element] where U.Iterator.Element == T {
return try sequence.flatMap(transform)
}

Expand All @@ -17,10 +17,10 @@ public func >>- <T, S: SequenceType, U: SequenceType where U.Generator.Element =

- returns: An array without optionals inside of it.
*/
public func compact<T, U: SequenceType where U.Generator.Element == T?> (sequence: U) -> [T] {
public func compact<T, U: Sequence> (_ sequence: U) -> [T] where U.Iterator.Element == T? {
return sequence.flatMap { return $0 }
}

public func -<< <T, S: SequenceType, U: SequenceType where U.Generator.Element == T> (transform: T throws -> S, sequence: U) rethrows -> [S.Generator.Element] {
public func -<< <T, S: Sequence, U: Sequence> (transform: (T) throws -> S, sequence: U) rethrows -> [S.Iterator.Element] where U.Iterator.Element == T {
return try sequence.flatMap(transform)
}
Loading