I think one of the best ways to learn about a tool is to use it by solving an interesting problem. The problem can be simple or complex based on how deep your curiosity is.
For me, the tool was wix/greyhound and the problem I wanted to solve was scheduling tasks using Kafka by providing schedules as Cron strings. As an additional constrain I did not want to use any other external storage other than Kafka.
One of the first problems we face is persisting the state of the app between restarts while keeping Kafka topic request payload small. …
When starting to developer apps in a different programming style, it’s common to get bog down by tooling and a multitude of libraries that promise to follow the pattern that you are preaching. This post plans to minimize this friction for Scala developers planning to create an Http service that would adhere to Functional Programming(FP) patterns.
As you can guess from the name of the post, we will be using Http4s for our Http layer and TSec for the authentication. For simplicity, we will use a single effect system Cats-Effect and transform our request payload to/from JSON with Circe. …
In the beginning, long before the rise of the great Serpent
Java, there existed a world filled only with the purest of creatures. They were bounded only by
types carved in their chains by their creators. They could move between streams without fear of affecting each other and only collaborate when the
types they were woven with allowed it.
Although for some, this life felt pointless as if it did not have any
effect . So some of the creatures filled with rage cast their shackles and morphed in the
When learning FP, it’s quite common to assume that modelling state mutation is hard. A simple value update in an imperative style can be hard to reason in pure FP code:
In small scope, imperative mutations look appealing, but what if we want to compose them. How would one even approach such a task? In that case, we would leverage our knowledge in functional composition by describing mutation as a function
type State[S, A] = S => (S, A). With this simple representation, we can express our program from above like this:
As you can see from the…
In programming, it’s quite common to express simple subsets of the system as predefined states and inputs that let your state transition from one state to another. It’s also quite pleasing to see your program as a diagram that then you can discuss with your co-workers. In this post, we will try to model a simple game of Hangman in a somewhat simple model using Finite State Machine(FSM) and Algebraic Data Types(ADTs) as building blocks. Our game might look something like this.
It tends to be hard to understand functional concepts without a context. And what’s a better setting than a simple game of TicTacToe. A quick reminder: TicTacToe is a game where you have a board of 9 squares, and you and your opponent are trying to fill the board with X’s or O’s in specific configurations. You can learn more about the rules and strategies on Wikipedia https://en.wikipedia.org/wiki/Tic-tac-toe.
Let’s start by defining our basic building block of the game as ADT:
sealed trait Squareobject X extends Square
object O extends Square
If we imagine the board at the beginning…
Scala developers might reach a point when they think the language is not letting them make the code more DRY(Don’t Repeat Yourself) and they have to drop their domain language and start using Factories and Builders or other ambiguous concepts. They end up copy-pasting some trivial boilerplate code around, or in some cases, go to the dark side and write macros that would generate the code for them and thus reduce the maintainability of the code. To work around this problem we can use 2 powerful concepts: Implicit Induction and Type Class Pattern.
It’s quite a common scenario to work with external API’s data, that is sometimes invalid. As developers we want to keep our code DRY(Don’t Repeat Yourself) and specific to our domain.
For example, we get a requirement to support a registration form, that consists of username and password. If they are valid, they should be part of some sort of computation in our system. In case of failure, we would like to know what exactly failed in the computation, was it the email, password or some other invalid computation.
Recently with my colleagues from Wix, I started reading about Typed Tagless Final Interpreters. As with any good material on programming paradigms, it is filled with complicated code examples and complex word constructs. So I decided to relieve some complexity by at least explaining some Haskell constructs used in the code.
Define syntax used to describe algebra.
data Bool = True | False
In the example above
Bool represents a data type and
False represents values it can be evaluated too. …
Twitter is one of the largest social platforms out there that can help you build your brand and online presence. As any good tool, it can be used as a catalyzer to grow your efforts or hindrance that stops you in your tracks. To make your life easier I wanted to share few tips I learned in recent Wix seminar about online presence.
#hashtags— lets you focus on particular topics
@mentions— help you link a person or brand
Re-tweet— a method of spreading content that you like to your followers
Follower— person subscribed to your Twitter…
Engineer that strives for excellence and growth. Currently working at @Wix and loving it!