Sequence Conformance

So you want to conform to SequenceType. Maybe you’re even more ambitious than that: CollectionType, MutableSliceable, RangeReplaceableCollectionType – you want it all. What’s involved?

Read More

Advertisements

A Trie in Swift

Morning panorama of the Eastern facade of Viborg Cathedral School

By Slaunger (Own work) CC BY-SA 4.0

(all code from this post available here)

If you google “cool data structures” you’ll get this as your first result. It’s a stackoverflow question: “What are the lesser known but useful data structures?”. And the top answer is a Trie. I read up on them, and found out a lot of cool things about their use (as well as finding out that I’m now the kind of person who googles “cool data structures”). So I rocked on up to my playground, and got writing.

Read More

Yet Another Root of All Evil

(All the code from this post is available here)

So I watched this video the other day:

 

It’s a great lecture. I’d recommend the whole thing. The main thrust of the talk is a theme that I’ve always had a little trouble with: performance. Performance is an odd topic in computer science: for something so obviously empirical, there’s an awful lot of (seeming) mysticism around some of the concepts. For beginners like me, it makes performance seem like an untouchable, too-difficult-for-you area.

Read More

Making FlatMap lazy

flatMap() is pretty cool. When I first learned what map() did, it got shoved into every line of code I had, regardless of how applicable it was. (That’s usually a good sign.) Then, along came flatMap(). It’s deceptively simple: its name pretty much explains exactly what it does. Useful, not game-changing, although it does let you do some pretty cool things:

Read More