import { Magma } from './Magma'
import { Ord } from './Ord'
import { ReadonlyRecord } from './ReadonlyRecord'
/**
* @category type classes
* @since 2.0.0
*/
export interface Semigroup extends Magma {}
/**
* Given a sequence of `as`, concat them and return the total.
*
* If `as` is empty, return the provided `startWith` value.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* const sum = S.fold(S.semigroupSum)(0)
*
* assert.deepStrictEqual(sum([1, 2, 3]), 6)
* assert.deepStrictEqual(sum([]), 0)
*
* @since 2.0.0
*/
export declare function fold(
S: Semigroup
): {
(startWith: A): (as: ReadonlyArray) => A
(startWith: A, as: ReadonlyArray): A
}
/**
* Always return the first argument.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* assert.deepStrictEqual(S.getFirstSemigroup().concat(1, 2), 1)
*
* @category instances
* @since 2.0.0
*/
export declare function getFirstSemigroup(): Semigroup
/**
* Always return the last argument.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* assert.deepStrictEqual(S.getLastSemigroup().concat(1, 2), 2)
*
* @category instances
* @since 2.0.0
*/
export declare function getLastSemigroup(): Semigroup
/**
* Given a tuple of semigroups returns a semigroup for the tuple.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* const S1 = S.getTupleSemigroup(S.semigroupString, S.semigroupSum)
* assert.deepStrictEqual(S1.concat(['a', 1], ['b', 2]), ['ab', 3])
*
* const S2 = S.getTupleSemigroup(S.semigroupString, S.semigroupSum, S.semigroupAll)
* assert.deepStrictEqual(S2.concat(['a', 1, true], ['b', 2, false]), ['ab', 3, false])
*
* @category instances
* @since 2.0.0
*/
export declare function getTupleSemigroup>>(
...semigroups: T
): Semigroup<
{
[K in keyof T]: T[K] extends Semigroup ? A : never
}
>
/**
* The dual of a `Semigroup`, obtained by swapping the arguments of `concat`.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* assert.deepStrictEqual(S.getDualSemigroup(S.semigroupString).concat('a', 'b'), 'ba')
*
* @category instances
* @since 2.0.0
*/
export declare function getDualSemigroup(S: Semigroup): Semigroup
/**
* Unary functions form a semigroup as long as you can provide a semigroup for the codomain.
*
* @example
* import { Predicate } from 'fp-ts/function'
* import * as S from 'fp-ts/Semigroup'
*
* const f: Predicate = (n) => n <= 2
* const g: Predicate = (n) => n >= 0
*
* const S1 = S.getFunctionSemigroup(S.semigroupAll)()
*
* assert.deepStrictEqual(S1.concat(f, g)(1), true)
* assert.deepStrictEqual(S1.concat(f, g)(3), false)
*
* const S2 = S.getFunctionSemigroup(S.semigroupAny)()
*
* assert.deepStrictEqual(S2.concat(f, g)(1), true)
* assert.deepStrictEqual(S2.concat(f, g)(3), true)
*
* @category instances
* @since 2.0.0
*/
export declare function getFunctionSemigroup(S: Semigroup): () => Semigroup<(a: A) => S>
/**
* Given a struct of semigroups returns a semigroup for the struct.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* interface Point {
* readonly x: number
* readonly y: number
* }
*
* const semigroupPoint = S.getStructSemigroup({
* x: S.semigroupSum,
* y: S.semigroupSum
* })
*
* assert.deepStrictEqual(semigroupPoint.concat({ x: 1, y: 2 }, { x: 3, y: 4 }), { x: 4, y: 6 })
*
* @category instances
* @since 2.0.0
*/
export declare function getStructSemigroup>(
semigroups: {
[K in keyof O]: Semigroup
}
): Semigroup
/**
* Get a semigroup where `concat` will return the minimum, based on the provided order.
*
* @example
* import * as O from 'fp-ts/Ord'
* import * as S from 'fp-ts/Semigroup'
*
* const S1 = S.getMeetSemigroup(O.ordNumber)
*
* assert.deepStrictEqual(S1.concat(1, 2), 1)
*
* @category instances
* @since 2.0.0
*/
export declare function getMeetSemigroup(O: Ord): Semigroup
/**
* Get a semigroup where `concat` will return the maximum, based on the provided order.
*
* @example
* import * as O from 'fp-ts/Ord'
* import * as S from 'fp-ts/Semigroup'
*
* const S1 = S.getJoinSemigroup(O.ordNumber)
*
* assert.deepStrictEqual(S1.concat(1, 2), 2)
*
* @category instances
* @since 2.0.0
*/
export declare function getJoinSemigroup(O: Ord): Semigroup
/**
* Return a semigroup for objects, preserving their type.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* interface Person {
* name: string
* age: number
* }
*
* const S1 = S.getObjectSemigroup()
* assert.deepStrictEqual(S1.concat({ name: 'name', age: 23 }, { name: 'name', age: 24 }), { name: 'name', age: 24 })
*
* @category instances
* @since 2.0.0
*/
export declare function getObjectSemigroup(): Semigroup
/**
* `boolean` semigroup under conjunction.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* assert.deepStrictEqual(S.semigroupAll.concat(true, true), true)
* assert.deepStrictEqual(S.semigroupAll.concat(true, false), false)
*
* @category instances
* @since 2.0.0
*/
export declare const semigroupAll: Semigroup
/**
* `boolean` semigroup under disjunction.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* assert.deepStrictEqual(S.semigroupAny.concat(true, true), true)
* assert.deepStrictEqual(S.semigroupAny.concat(true, false), true)
* assert.deepStrictEqual(S.semigroupAny.concat(false, false), false)
*
* @category instances
* @since 2.0.0
*/
export declare const semigroupAny: Semigroup
/**
* `number` semigroup under addition.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* assert.deepStrictEqual(S.semigroupSum.concat(2, 3), 5)
*
* @category instances
* @since 2.0.0
*/
export declare const semigroupSum: Semigroup
/**
* `number` semigroup under multiplication.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* assert.deepStrictEqual(S.semigroupProduct.concat(2, 3), 6)
*
* @category instances
* @since 2.0.0
*/
export declare const semigroupProduct: Semigroup
/**
* `string` semigroup under concatenation.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* assert.deepStrictEqual(S.semigroupString.concat('a', 'b'), 'ab')
*
* @category instances
* @since 2.0.0
*/
export declare const semigroupString: Semigroup
/**
* @category instances
* @since 2.0.0
*/
export declare const semigroupVoid: Semigroup
/**
* You can glue items between and stay associative.
*
* @example
* import * as S from 'fp-ts/Semigroup'
*
* const S1 = S.getIntercalateSemigroup(' ')(S.semigroupString)
*
* assert.strictEqual(S1.concat('a', 'b'), 'a b')
* assert.strictEqual(S1.concat(S1.concat('a', 'b'), 'c'), S1.concat('a', S1.concat('b', 'c')))
*
* @category instances
* @since 2.5.0
*/
export declare function getIntercalateSemigroup(a: A): (S: Semigroup) => Semigroup