All Projects → stephencelis → Formatting

stephencelis / Formatting

Licence: mit
Type-safe, functional string formatting in Swift.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Formatting

Curryhoward
Automatic code generation for Scala functions and expressions via the Curry-Howard isomorphism
Stars: ✭ 229 (-7.66%)
Mutual labels:  functional-programming
Cats Tagless
Library of utilities for tagless final encoded algebras
Stars: ✭ 238 (-4.03%)
Mutual labels:  functional-programming
Luaformatter
Code formatter for Lua
Stars: ✭ 244 (-1.61%)
Mutual labels:  formatter
Elm Ts
A porting to TypeScript featuring fp-ts, rxjs6 and React
Stars: ✭ 230 (-7.26%)
Mutual labels:  functional-programming
Unchanged
A tiny, fast, unopinionated handler for updating JS objects and arrays immutably
Stars: ✭ 237 (-4.44%)
Mutual labels:  functional-programming
Prettyhtml
💅 The formatter for the modern web https://prettyhtml.netlify.com/
Stars: ✭ 241 (-2.82%)
Mutual labels:  formatter
Program Blog
Practice, thinking and reading
Stars: ✭ 228 (-8.06%)
Mutual labels:  functional-programming
Suddi.github.io
A static single-page application resume-builder developed using React.js and JSON Resume schema (https://suddi.io/)
Stars: ✭ 246 (-0.81%)
Mutual labels:  functional-programming
Cats Mtl
cats transformer type classes.
Stars: ✭ 238 (-4.03%)
Mutual labels:  functional-programming
Typescript Express Starter
🚀 TypeScript Express Starter
Stars: ✭ 238 (-4.03%)
Mutual labels:  formatter
Poica
🧮 A research programming language on top of C macros
Stars: ✭ 231 (-6.85%)
Mutual labels:  functional-programming
Neither
Either and Maybe monads for better error-handling in C++ ↔️
Stars: ✭ 236 (-4.84%)
Mutual labels:  functional-programming
Ink
Ink is a minimal programming language inspired by modern JavaScript and Go, with functional style.
Stars: ✭ 243 (-2.02%)
Mutual labels:  functional-programming
Stringformatter
Simple Text Formetter (Credit Card Number, Phone Number, Serial Number etc.) Can be used in all text inputs according to the format pattern. If desired, large minor character restrictions can be made in the format pattern.
Stars: ✭ 231 (-6.85%)
Mutual labels:  formatter
Fsharp
The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
Stars: ✭ 2,966 (+1095.97%)
Mutual labels:  functional-programming
Arturo
Simple, expressive & portable programming language for efficient scripting
Stars: ✭ 225 (-9.27%)
Mutual labels:  functional-programming
Webpack Messages
Beautifully format Webpack messages throughout your bundle lifecycle(s)!
Stars: ✭ 238 (-4.03%)
Mutual labels:  formatter
Never
Never: statically typed, embeddable functional programming language.
Stars: ✭ 248 (+0%)
Mutual labels:  functional-programming
Pratica
🥃 Functional Algebraic Data Types
Stars: ✭ 246 (-0.81%)
Mutual labels:  functional-programming
Phunctional
⚡️ λ PHP functional library focused on simplicity and performance
Stars: ✭ 243 (-2.02%)
Mutual labels:  functional-programming

Formatting

Type-safe, functional string formatting in Swift.

Inspired by Chris Done's excellent Haskell library.

import Formatting

format("Hello, " % string % "!", "world")
// "Hello, world!"

Introduction

Traditional string formatting methods (interpolation, printf, and template strings) can lead to subtle (and not so subtle) runtime bugs.

print("Hello, \(thing)!")              // Hello, nil!
print("Hello, \(thing)!")              // Hello, Optional("world")!
NSLog(@"Hello, %@!", thing);           // Hello, (null)!

Formatting brings compile-time checks.

print("Hello, " % string % "!", thing) // Value of optional type String? not unwrapped

And composability.

let greet =
  format("Hello, " % string % "!")

greet("world")                         // Hello, world!

Composing formatters

Use % to build a formatter with strings and other formatters.

format(string % " is " % int % "years old.", "Alice", 25)
// "Alice is 25 years old."

Use <> to pass the previous formatter argument to the next formatter.

format(yyyy % "-" <> MM % "-" <> dd, Date())
// "2016-06-28"

Use .% to feed the result of one formatter into another.

format(left(2, "0") .% hex, 10)
// "0a"

Call format without arguments to return a curried formatter function.

let log =
  format(right(5) % " -- [" % iso8601 % "] " % string)

let infoLog = log("INFO")
let debugLog = log("DEBUG")

infoLog(Date())("Logging in...")
// "INFO  -- [2016-06-28T12:34:56Z] Logging in..."
debugLog(Date())("Logged in successfully!")
// "DEBUG -- [2016-06-28T12:34:56Z] Logged in successfully!"

License

Formatting is available under the MIT license. See the LICENSE file for more information.

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