Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/klntsky/purescript-balanced-fold
Folds a list of values, trying as much as possible to balance.
https://github.com/klntsky/purescript-balanced-fold
Last synced: 5 days ago
JSON representation
Folds a list of values, trying as much as possible to balance.
- Host: GitHub
- URL: https://github.com/klntsky/purescript-balanced-fold
- Owner: klntsky
- Created: 2019-03-31T12:26:25.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-24T15:50:13.000Z (over 5 years ago)
- Last Synced: 2024-11-09T15:47:42.567Z (2 months ago)
- Language: PureScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# purescript-balanced-fold [![Dependencies](https://img.shields.io/librariesio/github/klntsky/purescript-balanced-fold.svg)](https://libraries.io/github/klntsky/purescript-balanced-fold) [![Build status](https://travis-ci.org/klntsky/purescript-balanced-fold.svg?branch=master)](https://travis-ci.org/klntsky/purescript-balanced-fold)
A balanced fold, also called tree fold, is an operation of folding a list of values using some associative operation, trying as much as possible to balance.
Can be useful for constructing balanced binary trees, or more stable summation.
# Example
Given a binary tree,
```purescript
data T a = Empty | L a | B (T a) (T a)infixl 6 B as :*:
```which is an instance of `Semigroup` with `append = B` and `Monoid` with `mempty = Empty`,
```purescript
balancedFold (map L (1..5)) ≡ ((L 1) :*: (((L 2) :*: (L 3)) :*: ((L 4) :*: (L 5))))
```Check out [the tests](test/TestMain.purs) for more examples.
# See also:
1. [treefold](http://hackage.haskell.org/package/treefold) on Hackage.
# Module documentation
Browse [generated-docs](generated-docs/Data/BalancedFold.md).
PM me if you want this library to be on Pursuit.