All Projects → ulrikdamm → Forbind

ulrikdamm / Forbind

Licence: MIT license
Functional chaining and promises in Swift

Programming Languages

swift
15916 projects
objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Forbind

transceiver
Channel based event bus with request/reply pattern, using promises. For node & browser.
Stars: ✭ 25 (-43.18%)
Mutual labels:  promise
make-cancellable-promise
Make any Promise cancellable.
Stars: ✭ 17 (-61.36%)
Mutual labels:  promise
wxapp-socket
用于微信小程序socket通信的封装
Stars: ✭ 17 (-61.36%)
Mutual labels:  promise
hangman-game
A responsive hangman game built with vanilla javascript, html, and css. Animated with GSAP and canvas animations.
Stars: ✭ 22 (-50%)
Mutual labels:  promise
parcel-plugin-goodie-bag
provides the Promise and fetch goodies needed for IE(11) support w/ parcel bundle loading
Stars: ✭ 15 (-65.91%)
Mutual labels:  promise
codegen
Generator for dart_native bindings. Codegen can transform native SDK to Flutter plugin.
Stars: ✭ 75 (+70.45%)
Mutual labels:  binding
python-pytest-harvest
Store data created during your `pytest` tests execution, and retrieve it at the end of the session, e.g. for applicative benchmarking purposes.
Stars: ✭ 44 (+0%)
Mutual labels:  result
io-ts-promise
io-ts for developers who like Promises
Stars: ✭ 69 (+56.82%)
Mutual labels:  promise
emacs-promise
Promises/A+ for Emacs
Stars: ✭ 56 (+27.27%)
Mutual labels:  promise
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-54.55%)
Mutual labels:  promise
Promise.allSettled
ES Proposal spec-compliant shim for Promise.allSettled
Stars: ✭ 93 (+111.36%)
Mutual labels:  promise
conquerant
lightweight async/await for Clojure
Stars: ✭ 31 (-29.55%)
Mutual labels:  promise
ADM-treeView
Pure AngularJs TreeView
Stars: ✭ 30 (-31.82%)
Mutual labels:  promise
skinner
Skin export / import tools for Autodesk Maya
Stars: ✭ 68 (+54.55%)
Mutual labels:  binding
of
🍬 Promise wrapper with sugar 🍬
Stars: ✭ 13 (-70.45%)
Mutual labels:  promise
lightflow
A tiny Promise-inspired control flow library for browser and Node.js.
Stars: ✭ 29 (-34.09%)
Mutual labels:  promise
postmessagejs
postmessage-promise is a client-server like, WebSocket like, full Promise syntax (postMessage.then etc.) supported postMessage library. 一个类 client-server 模式、类 WebSocket 模式、全 Promise 语法支持的 postMessage 库
Stars: ✭ 33 (-25%)
Mutual labels:  promise
buzy
Async queue manager for node and browser
Stars: ✭ 23 (-47.73%)
Mutual labels:  promise
react-nested-loader
The easiest way to manage loaders/errors inside a button. NOT an UI lib.
Stars: ✭ 62 (+40.91%)
Mutual labels:  promise
microteam
小团队管理 是一款开源的微信小程序,主要用于日常的团队管理
Stars: ✭ 40 (-9.09%)
Mutual labels:  promise

Forbind

Functional chaining and promises in Swift

Note: still in an experimental state. Everything could change. I would love some feedback on this. Write to @ulrikdamm on Twitter.

What is it

Bind local or async expressions together functionally, all error handling taken care of for you:

func getUser(id : String) -> Promise<Result<User>> {
	let data = NSURL(string: id)
		=> { NSURLRequest(URL: $0) }
		=> NSURLConnection.sendRequest(.mainQueue())
		=> { response, data in data }
	
	return data
		=> NSJSONSerialization.toJSON(options: nil)
		=> { $0.dictionaryValue }
		=> User.fromJSON
}

• Bind operations together with =>

• No error handling inside your logic

• Transparent async calls

• No if-lets

• Combine inputs with ++

For more details, read my Blog post.

New in 1.1

• ResultPromise and OptionalPromise has been replaced with Promise<Result> and Promise<T?>. Still works the same.

• You can use the bind operator to map over lists of promises!

let user = User(name: "Ulrik")
let names = user.loadFriends() => { $0.name } // [Promise<String>]

• And you can also filter and reduce with filterp and reducep:

let someNames = filterp(names) { $0 != "Peter" } // Promise<[String]>

• The NSJSONSerialization extension now returns a JSONResult, which is either a Dictionary or Array.

Get started

You can add Forbind to your project using CocoaPods. Just add it to your Podfile:

use_frameworks!

pod 'Forbind', '~> 1.1'
pod 'ForbindExtensions', :git => 'https://github.com/ulrikdamm/Forbind'

(You need the use_frameworks! since that feature of CocoaPods is still in beta. ForbindExtensions are optional)

Or you can add it using Carthage by adding this to your cartfile:

github "ulrikdamm/Forbind" ~> 1.0

This will add both Forbind.framework and ForbindExtensions.framework, which you can drag into your Xcode project.

Then in your files just import Forbind and optionally ForbindExtensions

import Forbind
import ForbindExtensions

The Forbind library is the bind operator (=>) and the combine operator (++), along with the Result enum and Promise classes.

ForbindExtensions are extensions to Foundation and UIKit for working better with Forbind, by, for example, returning a promise instead of using a completion block. The ForbindExtensions are still a work in progress, so you might want to make your own extensions instead. In this case, just only include the Forbind framework.

What is the state of the project?

It’s still very experimental, so I would love some feedback on it. I wouldn’t recommend relying on this for product code yet. If you have a good idea, or just questions, submit a pull request or contact me at @ulrikdamm on Twitter.

Things that still needs to be considered:

• General direction of the project (are there some fundamental flaws?)

• Promise cancellation (support for cancelling an async operation if a promise is deallocated)

• Handling of dispatch queues (currently promise callbacks are run on the same queue as the operation finished on)

• More extensions for common UIKit/AppKit/Foundation methods to use Promise and Result instead of NSErrorPointer and completion blocks.

• "Expression was too complex to be solved in reasonable time" for big expressions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].