It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.
extension UIImageView { | |
func topAlignmentAndAspectFit(to view: UIView) { | |
self.contentMode = .scaleAspectFill | |
self.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(self) | |
self.addConstraints( | |
[NSLayoutConstraint(item: self, | |
attribute: .height, | |
relatedBy: .equal, |
public struct Event { | |
public internal(set) var timeStamp: Date | |
public internal(set) var eventTag: String | |
public init(timeStamp: Date, tag: String) { | |
self.timeStamp = timeStamp | |
self.eventTag = tag | |
} | |
} |
-
Shortened URL for this gist: https://git.io/v68XM
-
GitHub repository: ES6 in Motion
-
Arrow Functions
State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?
There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.
Here I present a composable pattern for pure state machiness with effects,
// if you coming from the Argo Talk from WTB Swift | |
// here is the actual playground code: https://github.com/zhigang1992/ArgoTalk | |
import Foundation | |
struct Parser<T> { | |
let parse: (AnyObject) -> T? | |
} |
/* | |
erica sadun ericasadun.com | |
Math Types | |
Swift2 | |
*/ | |
import Foundation | |
import QuartzCore |
When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.
So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.
Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?
I'm going to cover three things in this post: