All Projects → pointfreeco → Swift Prelude

pointfreeco / Swift Prelude

Licence: mit
🎶 A collection of types and functions that enhance the Swift language.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swift Prelude

Shapeless
Generic programming for Scala
Stars: ✭ 3,207 (+818.91%)
Mutual labels:  functional-programming
Here Be Dragons
An Intellij/Android Studio plugin to help visualise side effects in your code.
Stars: ✭ 325 (-6.88%)
Mutual labels:  functional-programming
Tsec
Type-safe general-cryptography library - https://jmcardon.github.io/tsec/
Stars: ✭ 338 (-3.15%)
Mutual labels:  functional-programming
Functional Fortran
Functional programming for modern Fortran
Stars: ✭ 311 (-10.89%)
Mutual labels:  functional-programming
Vertx Zero
Zero Framework:http://www.vertxup.cn
Stars: ✭ 320 (-8.31%)
Mutual labels:  functional-programming
Swiftz
Functional programming in Swift
Stars: ✭ 3,327 (+853.3%)
Mutual labels:  functional-programming
Kocircuit
Ko: A generic type-safe language for concurrent, stateful, deadlock-free systems and protocol manipulations
Stars: ✭ 305 (-12.61%)
Mutual labels:  functional-programming
Scriptum
A fool's scriptum on functional programming
Stars: ✭ 346 (-0.86%)
Mutual labels:  functional-programming
Effect
effect isolation in Python, to facilitate more purely functional code
Stars: ✭ 324 (-7.16%)
Mutual labels:  functional-programming
Rxswift
RxSwift를 스터디하는 공간
Stars: ✭ 335 (-4.01%)
Mutual labels:  functional-programming
Prelude Ts
Functional programming, immutable collections and FP constructs for typescript and javascript
Stars: ✭ 315 (-9.74%)
Mutual labels:  functional-programming
Monio
Async-capable IO monad for JS
Stars: ✭ 311 (-10.89%)
Mutual labels:  functional-programming
Underscore Java
java port of Underscore.js
Stars: ✭ 327 (-6.3%)
Mutual labels:  functional-programming
Quack
🐤 A multi-paradigm programming language with gradual and duck typing that targets PHP and JS
Stars: ✭ 309 (-11.46%)
Mutual labels:  functional-programming
Scala typeclassopedia
Abstractions and constructions from math (Category theory, Abstract algebra) implementations in Scala, minimal description, links to good explanations, links to implementations in other FP languages: Haskell, Idris, Purescript, non FP too: Java, C++ and to formalizations in proof assistants: Coq (UniMath, HoTT book), Cubical Agda.
Stars: ✭ 338 (-3.15%)
Mutual labels:  functional-programming
Coconut
Simple, elegant, Pythonic functional programming.
Stars: ✭ 3,422 (+880.52%)
Mutual labels:  functional-programming
Magic In Ten Mins
十分钟魔法练习
Stars: ✭ 327 (-6.3%)
Mutual labels:  functional-programming
Functionaltabledata
Declarative UITableViewDataSource implementation
Stars: ✭ 347 (-0.57%)
Mutual labels:  functional-programming
Hazel
Hazel, a live functional programming environment with typed holes
Stars: ✭ 340 (-2.58%)
Mutual labels:  functional-programming
Gubrak
⚙️ Golang functional utility library with syntactic sugar. It's like lodash, but for Go
Stars: ✭ 329 (-5.73%)
Mutual labels:  functional-programming

swift-prelude

Swift 5.1 Build Status @pointfreeco

A collection of frameworks to enhance the Swift language.

Stability

This library should be considered alpha, and not stable. Breaking changes will happen often.

Installation

import PackageDescription

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

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.

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].