typelift / focus Goto Github PK
View Code? Open in Web Editor NEWOptics for Swift
License: MIT License
Optics for Swift
License: MIT License
Adding an issue for this before submitting a PR since I'm not sure if disabling was intentional or not. If it was intentional, was there a reason for disabling it? It seems like being in the Xcode project settings it would not impact SPM builds.
import Swiftz
import Focus
func fanin<A, B, C>(_ l: @escaping (A) -> C, _ r: @escaping (B) -> C) -> Function<Either<A, B>, C> {
return Function.arr(l) ||| Function.arr(r)
}
The above fails to compile and there doesn't seem to be a way to specify which library you want the operator to come from since Swiftz.||| fails to compile.
***: error: ambiguous operator declarations found for operator
return Function.arr(l) ||| Function.arr(r)
^
:0: note: found this matching operator declaration
:0: note: found this matching operator declaration
***: error: operator is not a known binary operator
return Function.arr(l) ||| Function.arr(r)
The other Swift Lens framework, Monocle
, has taken to a data-accessor-esque implementation of Lenses, and I think there's something to the idea of including a record-accessor structure with Focus. Especially since Swift doesn't allow polymorphic type aliases, and Monomorphic lenses are just easier to reason about for the general Swift programmer.
Fetching https://github.com/typelift/Focus
error: the package https://github.com/typelift/Focus @ 0.4.0 contains revisioned dependencies:
https://github.com/typelift/SwiftCheck.git @ master
https://github.com/typelift/Operadics.git @ master
Only they need a new name now because STL.
Is there no way to lens through an optional? I've tried with Party.lpartyCaterer() • User.userName
and Party.lpartyCaterer() • _Some • User.userName
, to no avail.
// A party has a host, an optional caterer and an array of guests
class Party {
var host : User
var caterer : User?
var guests : [User]
init(h : User, c : User? = nil, g : [User] = []) {
host = h
caterer = c
guests = g
}
class func lpartyHost() -> Lens<Party, Party, User, User> {
let getter = { (party : Party) -> User in party.host }
let setter = { (party : Party, host : User) -> Party in Party(h: host, c: party.caterer, g: party.guests) }
return Lens(get: getter, set: setter)
}
class func lpartyCaterer() -> Lens<Party, Party, User?, User?> {
let getter = { (party : Party) -> User? in party.caterer }
let setter = { (party : Party, caterer : User?) -> Party in Party(h: party.host, c: caterer, g: party.guests) }
return Lens(get: getter, set: setter)
}
class func lpartyGuests() -> Lens<Party, Party, [User], [User]> {
let getter = { (party : Party) -> [User] in party.guests }
let setter = { (party : Party, guests : [User]) -> Party in Party(h: party.host, c: party.caterer, g: guests) }
return Lens(get: getter, set: setter)
}
}
class PartySpec : XCTestCase {
func testLens() {
let party = Party(h: User("max", 1, [], "one"))
let hostnameLens = Party.lpartyHost() • User.userName
XCTAssert(hostnameLens.get(party) == "max")
let updatedParty: Party = (Party.lpartyHost() • User.userName).set(party, "Max")
XCTAssert(hostnameLens.get(updatedParty) == "Max")
let catererLens = Party.lpartyCaterer() • User.userName
let cateredParty: Party = (Party.lpartyCaterer() • User.userName).set(party, "Marc")
XCTAssert(catererLens.get(updatedParty) == "Marc")
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.