Capriccio is a type of composition characterized by a certain freedom of realization.
Caprice is a library build with the intention of explore the functional programming world without constraint.
Add the following to your Podfile
:
source 'https://github.com/jrBordet/Sources.git'
source 'https://cdn.cocoapods.org/'
target 'Target' do
pod 'Caprice', '0.0.5'
end
pod install
A Lens
type and a bridge between the lens world and the Swift key path world.
struct Book: Equatable {
var id: Int
var title: String
var author: Author
}
struct Author: Equatable {
var name: String
var surname: String
}
extension Book {
static var galacticGuideForHitchhikers = Book(id: 2, title: "galactic guide for hitchhikers", author: .adams)
}
extension Author {
static var adams = Author(name: "Adams", surname: "Douglas")
}
let name = .galacticGuideForHitchhikers |> ^\Book.author.name
let newBook = .galacticGuideForHitchhikers |> \Book.author.name *~ "Adams Noël"
let authorName = .galacticGuideForHitchhikers |> ^\Book.author.name
let authorName = .stoicism |> (lens(\Book.author) >>> lens(\Author.name)).get
let authorName = .stoicism |> (lens(\Book.author.name)).get
let result: Book = .it |> \Book.author.name *~ "new author"
let newUser = lens(\User.id).set(0, user)
let surname = books
.filter(by(^\.author.name, "Massimo"))
.map(^\.author.surname)
.reduce("", +)
.lowercased()
// surname == "pigliucci"
Filters out elements whose value match a predicates.
let book = books.filter(by(^\.author.name, "Massimo"))
Sorts the elements with respect to a Comparable property.
let usersSorted = users.sorted(by: their(^\User.id, >))