All Projects → typelevel → Paiges

typelevel / Paiges

Licence: apache-2.0
an implementation of Wadler's a prettier printer

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Paiges

Involt
Inject hardware interactions directly into HTML layout.
Stars: ✭ 128 (-16.34%)
Mutual labels:  layout
Motionlayoutsamples
A sample to take you to appreciate the charm of MotionLayout.
Stars: ✭ 135 (-11.76%)
Mutual labels:  layout
Bsp Layout
Manage layouts in bspwm (tall and wide)
Stars: ✭ 145 (-5.23%)
Mutual labels:  layout
Popo
PoPo is the grid layout tool, the best choice for runtime layout.
Stars: ✭ 130 (-15.03%)
Mutual labels:  layout
Pinlayout
Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]
Stars: ✭ 1,870 (+1122.22%)
Mutual labels:  layout
Vlayout
Project vlayout is a powerfull LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate situation when grid, list and other layouts in the same recyclerview.
Stars: ✭ 10,818 (+6970.59%)
Mutual labels:  layout
Greedo Layout For Android
Full aspect ratio grid LayoutManager for Android's RecyclerView
Stars: ✭ 1,588 (+937.91%)
Mutual labels:  layout
Swipelayout
A library what allows you to execute a swipe for the android platform
Stars: ✭ 150 (-1.96%)
Mutual labels:  layout
Framezilla
Elegant library that wraps working with frames with a nice chaining syntax.
Stars: ✭ 134 (-12.42%)
Mutual labels:  layout
Ololog
A better console.log for the log-driven debugging junkies
Stars: ✭ 141 (-7.84%)
Mutual labels:  pretty-print
Widgetlayout
自定义ViewGroup的集合(有 kotlin 实现分支):提高编写效率和 UI 绘制性能,少嵌套,易用易扩展。
Stars: ✭ 130 (-15.03%)
Mutual labels:  layout
Arclayout
With Arc Layout explore new styles and approaches on material design
Stars: ✭ 1,662 (+986.27%)
Mutual labels:  layout
Uistatus
一个简单且强大的Ui状态视图控制库!
Stars: ✭ 137 (-10.46%)
Mutual labels:  layout
Ast Pretty Print
A pretty printer for AST-like structures
Stars: ✭ 129 (-15.69%)
Mutual labels:  pretty-print
Binpp
🔢 Erlang Binary Pretty Printer
Stars: ✭ 148 (-3.27%)
Mutual labels:  pretty-print
Xray React
React layout debugger.
Stars: ✭ 128 (-16.34%)
Mutual labels:  layout
Popuplayout
通用弹出布局辅助库,允许开发者从顶部、底部、左侧、右侧和中心这五个位置弹出自己指定的View。The general pop-up Layout Assistant library allows developers to show their own view from the top, bottom, left, right and center five locations.
Stars: ✭ 135 (-11.76%)
Mutual labels:  layout
Phpunit Pretty Print
✅  Make your PHPUnit output beautiful
Stars: ✭ 149 (-2.61%)
Mutual labels:  pretty-print
Flourish
🎩 Flourish implements dynamic ways to show up and dismiss layouts with animations.
Stars: ✭ 150 (-1.96%)
Mutual labels:  layout
Android Statefullayout
A custom Android ViewGroup to display different states of screen (CONTENT, PROGRESS, OFFLINE, EMPTY, etc.)
Stars: ✭ 140 (-8.5%)
Mutual labels:  layout

Paiges

Overview

Paiges is an implementation of Wadler's "A Prettier Printer".

The library is useful any time you find yourself generating text or source code where you'd like to control the length of lines (e.g. paragraph wrapping).

The name Paiges is a reference to the Paige compositor and the fact that it helps you layout pages.

Build Status codecov.io Latest version

Quick Start

Paiges supports Scala 2.11, 2.12, and 2.13. It supports both the JVM and JS platforms.

To use Paiges in your own project, you can include this snippet in your build.sbt file:

// use this snippet for the JVM
libraryDependencies += "org.typelevel" %% "paiges-core" % "0.3.0"

// use this snippet for JS, or cross-building
libraryDependencies += "org.typelevel" %%% "paiges-core" % "0.3.0

Paiges also provides types to work with Cats via the paiges-cats module:

// use this snippet for the JVM
libraryDependencies += "org.typelevel" %% "paiges-cats" % "0.3.0"

// use this snippet for JS, or cross-building
libraryDependencies += "org.typelevel" %%% "paiges-cats" % "0.3.0"

Description

This code is a direct port of the code in section 7 of this paper, with an attempt to be idiomatic in scala while preserving the original code's properties, including laziness.

This algorithm is optimal and bounded. From the paper:

Say that a pretty printing algorithm is optimal if it chooses line breaks so as to avoid overflow whenever possible; say that it is bounded if it can make this choice after looking at no more than the next w characters, where w is the line width. Hughes notes that there is no algorithm to choose line breaks for his combinators that is optimal and bounded, while the layout algorithm presented here has both properties.

Some selling points of this code:

  1. Lazy, O(1) concatenation
  2. Competitive performance (e.g. 3-5x slower than mkString)
  3. Elegantly handle indentation
  4. Flexible line-wrapping strategies
  5. Functional cred ;)

Examples

Here's an example of using Paiges to generate the source code for a case class:

import org.typelevel.paiges._

/**
 * Produces a case class given a name and zero-or-more
 * field/type pairs.
 */
def mkCaseClass(name: String, fields: (String, String)*): Doc = {
  val prefix = Doc.text("case class ") + Doc.text(name) + Doc.char('(')
  val suffix = Doc.char(')')
  val types = fields.map { case (k, v) =>
    Doc.text(k) + Doc.char(':') + Doc.space + Doc.text(v)
  }
  val body = Doc.intercalate(Doc.char(',') + Doc.line, types)
  body.tightBracketBy(prefix, suffix)
}

val c = mkCaseClass(
  "Dog", "name" -> "String", "breed" -> "String",
  "height" -> "Int", "weight" -> "Int")

c.render(80)
// case class Dog(name: String, breed: String, height: Int, weight: Int)

c.render(60)
// case class Dog(
//   name: String,
//   breed: String,
//   height: Int,
//   weight: Int
// )

For more examples, see the tutorial.

Benchmarks

The Paiges benchmarks are written against JMH. To run them, you'll want to use a command like this from SBT:

benchmark/jmh:run -wi 5 -i 5 -f1 -t1 bench.PaigesBenchmark

By default the values reported are ops/ms (operations per millisecond), so higher numbers are better.

The parameters used here are:

  • -wi: the number of times to run during warmup
  • -i: the number of times to benchmark
  • -f: the number of processes to use during benchmarking
  • -t: the number of threads to use during benchmarking

In other words, the example command-line runs one thread in one process, with a relatively small number of warmups + runs (so that it will finish relatively quickly).

Organization

The current Paiges maintainers are:

People are expected to follow the Typelevel Code of Conduct when discussing Paiges on the Github page or other official venues.

Concerns or issues can be sent to any of Paiges' maintainers, or to the Typelevel organization.

License

Paiges is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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