Focus alternatives and similar libraries
Based on the "Utility" category.
Alternatively, view Focus alternatives based on common mentions on social networks and blogs.
-
SwifterSwift
A handy collection of more than 500 native Swift extensions to boost your productivity. -
SwiftGen-Storyboard
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs! -
R.swift
Strong typed, autocompleted resources like images, fonts and segues in Swift projects -
SwiftGen
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs! -
swift-protobuf
Plugin and runtime library for using protobuf with Swift -
Dollar
A functional tool-belt for Swift Language similar to Lo-Dash or Underscore.js in Javascript -
EZSwiftExtensions
:smirk: How Swift standard types and classes were supposed to work. -
DifferenceKit
💻 A fast and flexible O(n) difference algorithm framework for Swift collection. -
DeepDiff
🦀Amazingly incredible extraordinary lightning fast diffing in Swift -
Device
Light weight tool for detecting the current device and screen size written in swift. -
SwiftLinkPreview
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images. -
WhatsNew
Showcase new features after an app update similar to Pages, Numbers and Keynote. -
Codextended
Extensions giving Swift's Codable API type inference super powers 🦸♂️🦹♀️ -
SwiftyJSONAccelerator
macOS app to generate Swift 5 code for models from JSON (with Codeable) -
Playbook
📘A library for isolated developing UI components and automatically taking snapshots of them. -
ReadabilityKit
Preview extractor for news, articles and full-texts in Swift -
ObjectiveKit
Swift-friendly API for a set of powerful Objective C runtime functions. -
Compass
:earth_africa: Compass helps you setup a central navigation system for your application -
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift -
Pythonic.swift
Pythonic tool-belt for Swift – a Swift implementation of selected parts of Python standard library. -
Prototope
Swift library of lightweight interfaces for prototyping, bridged to JS.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Focus or a related project?
Popular Comparisons
README
Focus
Focus is an Optics library for Swift (where Optics includes Lens
,
Prism
s, and Iso
s) that is inspired by Haskell's
Lens library.
Introduction
Focus exports a number of primitives that make it easy to establish
relations between types. Practically, a relation can be thought of
as a particular way of viewing and modifying a structure. The most
famous of these is a Lens
or Functional Reference. While there are
an abundance of representations of a Lens (see
[van Laarhoven 09],
[Kmett et al. 12],
[Eidhof et al. 09], we
have chosen a
data-lens-like
implementation using the Indexed Store Comonad. If all of that makes
no sense, don't worry! We have hidden all of this behind a simple
interface.
Programming With Lenses
The easiest way to explain a lens is with a pair of functions
func get(structure : S) -> A
func set(pair : (self : S, newValue : A)) -> S
This should look quite familiar to you! After all, Swift includes syntax for this very pattern
final class Foo {
var bar : Qux {
get { //.. }
set(newValue) { //.. }
}
}
So what a lens actually lets you do is decouple the ability to focus
on particular bits and pieces of your data types. Moreover, lenses,
like properties, compose freely with other compatible lenses but with
normal function composition (denoted •
) instead of the usual
dot-notation. What sets Lenses apart from straight properties is
every part of the process is immutable. A lens performs replacement
of the entire structure, a property performs replacement of a mutable
value within that structure.
All of these properties, flexibility immutability, and composability, come together to enable a powerful set of operations that allow the programmer to view a structure and its parts at any depth and any angle, not simply those provided by properties.
Practical Lenses
For example, say we have this set of structures for working with a flight tracking app:
import Foundation
import Focus
enum Status {
case Early
case OnTime
case Late
}
struct Plane {
let model : String
let freeSeats : UInt
let takenSeats : UInt
let status : Status
var totalSeats : UInt {
return self.freeSeats + self.takenSeats
}
}
struct Gate {
let number : UInt
let letter : Character
}
struct BoardingPass {
let plane : Plane
let gate : Gate
let departureDate : NSDate
let arrivalDate : NSDate
}
Starting with a BoardingPass
, getting our flight status is trivial
let plane = Plane(model: "SpaceX Raptor", freeSeats: 4, takenSeats: 0, status: .OnTime)
let gate = Gate(number: 1, letter: "A")
let pass = BoardingPass(plane: plane
, gate: gate
, departureDate: NSDate.distantFuture()
, arrivalDate: NSDate.distantFuture())
let status = pass.plane.status
However, in order to update the status on the boarding pass without lenses, we'd have to go through this rigamarole every time:
let oldPass = BoardingPass(/* */)
// Apparently, we're actually flying Allegiant
let newFlight = Plane(model: oldPass.plane.model
, freeSeats: oldPass.plane.freeSeats
, takenSeats: oldPass.plane.takenSeats
, status: .Late)
let newPass = BoardingPass(plane: newFlight
, gate: oldPass.gate
, departureDate: oldPass.departureDate
, arrivalDate: oldPass.arrivalDate)
After defining a few lenses, this is what we can do instead:
// The composite of two lenses is itself a lens
let newPass = (BoardingPass._plane • Plane._status).set(oldPass, .Late)
Here's the definition of those lenses:
extension BoardingPass {
static var _plane : SimpleLens<BoardingPass, Plane> {
return SimpleLens(get: {
return $0.plane
}, set: { (oldPass, newP) in
return BoardingPass(plane: newP
, gate: oldPass.gate
, departureDate: oldPass.departureDate
, arrivalDate: oldPass.arrivalDate)
})
}
}
extension Plane {
static var _status : SimpleLens<Plane, Status> {
return SimpleLens(get: {
return $0.status
}, set: { (oldP, newS) in
return Plane( model: oldP.model
, freeSeats: oldP.freeSeats
, takenSeats: oldP.takenSeats
, status: newS)
})
}
}
We've only scratched the surface of the power of Lenses, and we haven't even touched the other members of the family of optics exported by Focus. For more on the Lens Family, check out the additional sources below and the implementation files for each family member.
Further Reading
- The Lens Library's website.
- Aditya Bhargava's marvelous illustrated guide to lenses.
- Haskell for All's Gabriel Gonzalez explains how to program imperatively using lenses
- Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire.
- Edward Kmett's talk on Lenses, Folds, and Traversals.
- In fact, pretty much everything Edward Kmett has talked about.
System Requirements
Focus supports OS X 10.9+ and iOS 8.0+.
License
Focus is released under the MIT license.
*Note that all licence references and agreements mentioned in the Focus README section above
are relevant to that project's source code only.