Skip to content

Commit

Permalink
FIx coeffect
Browse files Browse the repository at this point in the history
  • Loading branch information
Elviro Rocca committed May 11, 2018
1 parent 09373d9 commit 2282dc1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Sources/FunctionalKit/AnyError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
#endif
import Abstract

/// AnyError
///
/// A concrete type wrapping Error
///
/// This can be useful for parametrized types/functions where a parameter is constrained to Error:
/// since Error as a first-class type cannot be used in that position, the instance can be wrapped into AnyError.
public struct AnyError: Wrapper, Error {
public typealias WrappedType = Error
public let unwrap: Error
Expand Down
7 changes: 7 additions & 0 deletions Sources/FunctionalKit/Boolean.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
import Abstract

public extension Bool {
/// Method version of &&
func and(_ other: @autoclosure () -> Bool) -> Bool {
return self && other()
}

/// Method version of ||
func or(_ other: @autoclosure () -> Bool) -> Bool {
return self || other()
}

/// Computed property representing the negation (like the ! prefix, or "== false")
var not: Bool {
return self == false
}

/// Method version of =>
func implies(_ other: @autoclosure () -> Bool) -> Bool {
return self.not.or(other())
}

/// Logical implication
///
/// P => Q is equivalent to ¬PvQ
static func => (_ left: Bool, _ right: @autoclosure () -> Bool) -> Bool {
return left.implies(right())
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/FunctionalKit/Coeffect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct Coeffect<Parameter> {
}

public func run(_ environment: Parameter) {
call(environment)
_call(environment)
}
}

Expand Down

0 comments on commit 2282dc1

Please sign in to comment.