Componentix logo

Componentix blog

Here we write some random thoughts and articles about software development: Java, Grails, Node.js, iPhone, iPad and more.

Not so Swift – implementing transducers in Apple's new language

Motivation

Clojure's transducers represent an elegant and high-efficient way to transform data. JS implementation fared well, so I decided to try implementing them in Swift as well.

Examples

transduce(
    map({$0 + 1}) |>
    filter({$0 % 2 == 0}) |>
    map({$0 * 2}), append, [], [1, 2, 3, 4, 5])

// [4, 8, 12]

Code above is roughly equvivalent to following code with regular map / filter calls:

[1, 2, 3, 4, 5]
    .map({$0 + 1})
    .filter({$0 % 2 == 0})
    .map({$0 * 2})

Problems with Swift

Types. Swift is strongly typed so we get function signatures like this one:

func transduce<AccumType, ElemType1, ElemType2> (
        tfn : Transducer<AccumType, ElemType1, ElemType2>,
        rfn : (AccumType, ElemType2) -> AccumType,
    initial : AccumType, arr : [ElemType1]) -> AccumType]

I doubt anyone would find it nice.

Performance is even bigger problem for now. Currently it is anything but ready for production use.
As tested on Xcode Version 6.1.1 (6A2008a), it is at least 100x worse than standard map / filter chain.

Further info

See transducers implementation in this GitHub repo.

Scary Colors – coloring book app for iPad

We’ve been long developing iOS apps for various clients and now finally released something own in the AppStore. It’s a coloring book for children, dedicated to Halloween theme.

There is a lot of similar apps, however we have some unique feature, that I wanted since I was child – color stays inside of lines when painting :)

See it here: http://happycolorsapp.com

Tags: ipad ios kids

Design interfaces of iPad apps on paper

If you like drawing UI sketches on paper and plan to design iPad applications, there is a sketchbook for it - http://www.ipadsketchbook.com/

Sketchbook sheets have the layout of iPad in actual size printed on the front. iPad screen is covered with grid which allows to lay out interface elements conveniently. On the back sheets are just covered with simple square grid for comments, various thoughts, design of individual elements, etc.

Technical specs (better than iPad in many aspects):

  • 42 A4 sheets
  • actual size of iPad
  • convenient grid
  • multitasking support
  • zero-watt consumption
Following e-mail is only for robots (never send anything to it, or you would be blacklisted): botsonly@componentix.com