• Stars
    star
    456
  • Rank 92,638 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎢 A collection of types and functions that enhance the Swift language.

swift-prelude

Swift 5.1 CI @pointfreeco

A collection of frameworks to enhance the Swift language.

Stability

This library should be considered experimental. If you find its contents useful, please consider maintaining a fork.

Installation

import PackageDescription

let package = Package(
  dependencies: [
    .package(url: "https://github.com/pointfreeco/swift-prelude.git", .branch("main")),
  ]
)

Table of Contents

Prelude

A collection of types and functions to build powerful abstractions and enhance the Swift standard library.

Either

A type to express a value that holds one of two other types.

import Either

let intOrString = Either<Int, String>.left(2)

intOrString
  .bimap({ $0 + 1 }, { $0 + "!" }) // => .left(3)

Optics

A Lens type and a bridge between the lens world and the Swift key path world.

import Optics
import Prelude

struct User {
  var id: Int
  var name: String
}

let uppercased: (String) -> String = { $0.uppercased() }

let user = User(id: 1, name: "Blob")

user
  |> \.id .~ 2
  |> \.name %~ uppercased

// => User(2, "BLOB")

ValidationSemigroup

The Validation<E, A> type is a type similar to Result<E, A>, except it is given a different applicative instance in the case that E is a semigroup. This allows you to accumulate multiple errors into E instead of just taking the first error:

import Prelude
import ValidationSemigroup

struct User { let name: String; let bio: String; let email: String }
let createUser = { name in { bio in { email in User(name: name, bio: bio, email: email) } } }

func validate(name: String) -> Validation<[String], String> {
  return !name.isEmpty
    ? pure(name)
    : .invalid(["Name must be at least 1 character."])
}

func validate(bio: String) -> Validation<[String], String> {
  return bio.count <= 10
    ? pure(bio)
    : .invalid(["Bio must 10 characters or less."])
}

func validate(email: String) -> Validation<[String], String> {
  return email.contains("@")
    ? pure(email)
    : .invalid(["Email must be valid."])
}

let validUser = pure(createUser)
  <*> validate(name: "Blob")
  <*> validate(bio: "I'm a blob")
  <*> validate(email: "[email protected]")
// => .valid(User(name: "Blob", bio: "I'm a blob", email: "[email protected]"))

let invalidUser = pure(createUser)
  <*> validate(name: "Blob")
  <*> validate(bio: "Blobbin around the world")
  <*> validate(email: "blob")
// => .invalid(["Bio must 10 characters or less.", "Email must be valid."])

For more information, watch Stephen Celis’ talk.

ValidationNearSemiring

This Validation<E, A> type is a type similar to Result<E, A> and the above Validation, except it is given a different applicative instance in the case that E is a NearSemiring. This allows you to accumulate errors that describe conditions that hold with both β€œand” and β€œor”, e.g. name is required and either email or phone is required.

License

All modules are released under the MIT license. See LICENSE for details.

More Repositories

1

swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
Swift
10,990
star
2

swift-snapshot-testing

πŸ“Έ Delightful Swift snapshot testing.
Swift
3,559
star
3

isowords

Open source game built in SwiftUI and the Composable Architecture.
Swift
2,515
star
4

swiftui-navigation

Tools for making SwiftUI navigation simpler, more ergonomic and more precise.
Swift
1,654
star
5

swift-dependencies

A dependency management library inspired by SwiftUI's "environment."
Swift
1,322
star
6

swift-tagged

🏷 A wrapper type for safer, expressive code.
Swift
1,289
star
7

swift-overture

🎼 A library for function composition.
Swift
1,115
star
8

pointfreeco

🎬 The source for www.pointfree.co, a video series on functional programming and the Swift programming language.
Swift
1,054
star
9

episode-code-samples

πŸ’Ύ Point-Free episode code.
Swift
922
star
10

swift-case-paths

🧰 Case paths extends the key path hierarchy to enum cases.
Swift
852
star
11

swift-nonempty

🎁 A compile-time guarantee that a collection contains a value.
Swift
817
star
12

swift-parsing

A library for turning nebulous data into well-structured data, with a focus on composition, performance, generality, and ergonomics.
Swift
802
star
13

swift-custom-dump

A collection of tools for debugging, diffing, and testing your application's data structures.
Swift
766
star
14

swift-html

πŸ—Ί A Swift DSL for type-safe, extensible, and transformable HTML documents.
Swift
726
star
15

combine-schedulers

⏰ A few schedulers that make working with Combine more testable and more versatile.
Swift
671
star
16

swift-web

πŸ•Έ A collection of Swift server-side frameworks for handling HTML, CSS, routing and middleware.
Swift
477
star
17

swift-identified-collections

A library of data structures for working with collections of identifiable elements in an ergonomic, performant way.
Swift
476
star
18

swift-perception

Observable tools, backported.
Swift
399
star
19

swift-validated

πŸ›‚ A result type that accumulates multiple errors.
Swift
389
star
20

swift-url-routing

A bidirectional router with more type safety and less fuss.
Swift
321
star
21

swift-concurrency-extras

Useful, testable Swift concurrency.
Swift
267
star
22

swift-gen

🎱 Composable, transformable, controllable randomness.
Swift
262
star
23

swift-clocks

⏰ A few clocks that make working with Swift concurrency more testable and more versatile.
Swift
229
star
24

swift-enum-properties

🀝 Struct and enum data access in harmony.
Swift
198
star
25

xctest-dynamic-overlay

Define XCTest assertion helpers directly in your application and library code.
Swift
197
star
26

swift-macro-testing

Magical testing tools for Swift macros.
Swift
192
star
27

syncups

A rebuild of Apple’s β€œScrumdinger” application using modern, best practices for SwiftUI development.
Swift
153
star
28

composable-core-location

A library that bridges the Composable Architecture and Core Location.
Swift
100
star
29

vapor-routing

A bidirectional Vapor router with more type safety and less fuss.
Swift
83
star
30

swift-html-vapor

πŸ’§ Vapor plugin for type-safe, transformable HTML views.
Swift
82
star
31

swift-playground-templates

🏫 A collection of helpful Xcode playground templates.
Makefile
80
star
32

pointfreeco-server

Point-Free server code.
39
star
33

swift-boundaries

🐣 Functional core, imperative shell.
Swift
27
star
34

composable-core-motion

A library that bridges the Composable Architecture and Core Motion.
Swift
26
star
35

swift-quickcheck

🏁 An implementation of QuickCheck in Swift.
Swift
24
star
36

swift-algebras

Algebraic laws bundled into concrete data types.
19
star
37

swift-either

For those times you want A or B!
Swift
19
star
38

swift-parser-printer

↔️ Parsing and printing
Swift
14
star
39

swift-html-kitura

☁️ Kitura plugin for type-safe, transformable HTML views.
Swift
13
star
40

homebrew-swift

Ruby
2
star
41

swift-bugs

2
star
42

Ccmark

Swift
1
star