Don't Fear Custom Operator!

Table of Contents Introduction Creating custom operator Operator overload (The bad) Operator overload (The good) Custom Operator Normal composition Direct composition Left to Right application operator Creating Custom Operator |> 3 Q’s before introducing custom operator Custom operator for map fmap or map |» operator Conclusion Introduction Operator (+, -, >) are just normal functions. Treated a bit differently (syntatically) by the compiler.

Read More

Extensible Analytics Library Design with Tagless final concept

Table of Contents Keywords Expression Problem Introduction Following the ritual Not following the ritual Preface 2 classical ways to implement analytics library Enum based (Sum type based) Class, struct+protocol based (product type based) Client problem: Add ForceTapEvent & support another analytics service The limitation of enum approach The limitation of class/(struct+protocol) based approach Summarizing A radical way to solve the same issue aka Tagless final Lets get both: ability to add cases and new interpretation.

Read More

Testable Interface design with Enums

Table of Contents Writing Testable Swift API with Enums Modeling interface based on Enum Using the OneTapFeature Testing Feature Refactoring the OneTapFearure to make it testable How about testing the present() What if our client module is using Obj-C Is the feature modular? Can it be resused by other apps? Conclusion Writing Testable Swift API with Enums Encapsulate everything and try to show as little as possible. Greedy approach.

Read More

Precision Timing in iOS & Swift

Time is what we want most, but what we use worst. -William Pen Timestamp is a very important issue we deal with in every single iOS/OSX project. Unlike timestamp, sometimes we want to measure method performance. Practically, i would use it for fun exploration. However, there are cases especially in games development where the precise time helps maintain consistent gameplay with scores. I explored a bit on how we can leverage the systems provided APIs to just get the current time stamp as precisely as possible.

Read More