Giter Site home page Giter Site logo

mswift's Introduction

mSwift

A simple eDSL introducing functional approach to pure calculations with Optional and Array types.

Installation

StickyView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'mSwift', :git => 'https://github.com/swordfishyou/mSwift.git'

Motivation

Functional languages like Haskell or Erlang have robust and clear syntax for pure computations. Such code is easy to understand, it's clear and doesn't break control flow. On a daily basis we don't perform pure computations, but when we do we write a lot of code. This small eDSL is designed to stay DRY in such cases.

Optional

Swift's optional binding and common usage often preferable for clarity and style. But Optional is a container type for a reason: it preserves specific context. The context is:

  • it's OK for Optional value to absent,
  • one doesn't use Optional for error handling.

guard let and if let force you to unwrap the box and handle the absence of a value. Moreover, so called optional binding is implemented as conditional statement, so it breaks control flow.

Array

We often use Array as a collection of objects, to keep some order, etc. Only on a rare occasion we use pure Array as designed: for non-deterministic computations.

Consider number 5. It's a deterministic value, it has just one result and we know it's 5. If we multiply it by another deterministic value like 3 we have another deterministic value 15. All these numbers have only one result. On the onther hand array [3, 5] contains two elements and if we perform multiplication by another array [1, 10, 100] we have an array with even more elements [3, 5, 30, 50, 300, 500]. Now you can see that Array is also a container type like Optional. Like any container type it also preserves a context:

  • there might be multiple elements in a single Array value,
  • the number of elements in a resulting Array may differ from initial values.

Since functional API is really handy we often prefer it over loops. Unfortunately, Swift lacks a number of robust sugar available in functional languages.

Implementation

mSwift introduces currying and a set of operators influenced by Haskell in order to apply functions in a pipeline.

mswift's People

Contributors

atu155 avatar

Watchers

James Cloos avatar Anatoly Tukhtarov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.