Semigroup
Instances
Constructors
Model
Utilities
- concatAll
fold(deprecated)getDualSemigroup(deprecated)getFirstSemigroup(deprecated)getFunctionSemigroup(deprecated)getIntercalateSemigroup(deprecated)getJoinSemigroup(deprecated)getLastSemigroup(deprecated)getMeetSemigroup(deprecated)getObjectSemigroup(deprecated)getStructSemigroup(deprecated)getTupleSemigroup(deprecated)- intercalate
- reverse
semigroupAll(deprecated)semigroupAny(deprecated)semigroupProduct(deprecated)semigroupString(deprecated)semigroupSum(deprecated)semigroupVoid(deprecated)- struct
- tuple
Instances
first
Always return the first argument.
Signature
export declare const first: <A = never>() => Semigroup<A>
Details
- Added in 0.1.0
Example
import * as S from '@fp-tx/core/Semigroup'
assert.deepStrictEqual(S.first<number>().concat(1, 2), 1)
License
- MIT – Copyright (c) 2017-present Giulio Canti
last
Always return the last argument.
Signature
export declare const last: <A = never>() => Semigroup<A>
Details
- Added in 0.1.0
Example
import * as S from '@fp-tx/core/Semigroup'
assert.deepStrictEqual(S.last<number>().concat(1, 2), 2)
License
- MIT – Copyright (c) 2017-present Giulio Canti
Constructors
constant
Signature
export declare const constant: <A>(a: A) => Semigroup<A>
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
max
Get a semigroup where concat
will return the maximum, based on the provided order.
Signature
export declare const max: <A>(O: Or.Ord<A>) => Semigroup<A>
Details
- Added in 0.1.0
Example
import * as N from '@fp-tx/core/number'
import * as S from '@fp-tx/core/Semigroup'
const S1 = S.max(N.Ord)
assert.deepStrictEqual(S1.concat(1, 2), 2)
License
- MIT – Copyright (c) 2017-present Giulio Canti
min
Get a semigroup where concat
will return the minimum, based on the provided order.
Signature
export declare const min: <A>(O: Or.Ord<A>) => Semigroup<A>
Details
- Added in 0.1.0
Example
import * as N from '@fp-tx/core/number'
import * as S from '@fp-tx/core/Semigroup'
const S1 = S.min(N.Ord)
assert.deepStrictEqual(S1.concat(1, 2), 1)
License
- MIT – Copyright (c) 2017-present Giulio Canti
Model
Semigroup
Signature
export interface Semigroup<A> extends Magma<A> {}
Details
- Added in 0.1.0
License
- MIT – Copyright (c) 2017-present Giulio Canti
Utilities
concatAll
Given a sequence of as
, concat them and return the total.
If as
is empty, return the provided startWith
value.
Signature
export declare const concatAll: <A>(S: Semigroup<A>) => (startWith: A) => (as: ReadonlyArray<A>) => A
Details
- Added in 0.1.0
Example
import { concatAll } from '@fp-tx/core/Semigroup'
import * as N from '@fp-tx/core/number'
const sum = concatAll(N.SemigroupSum)(0)
assert.deepStrictEqual(sum([1, 2, 3]), 6)
assert.deepStrictEqual(sum([]), 0)
License
- MIT – Copyright (c) 2017-present Giulio Canti
fold
fold
Use concatAll
instead.
Signature
export declare function fold<A>(S: Semigroup<A>): {
(startWith: A): (as: ReadonlyArray<A>) => A
(startWith: A, as: ReadonlyArray<A>): A
}
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getDualSemigroup
getDualSemigroup
Use reverse
instead.
Signature
export declare const getDualSemigroup: <A>(S: Semigroup<A>) => Semigroup<A>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getFirstSemigroup
getFirstSemigroup
Use first
instead.
Signature
export declare const getFirstSemigroup: <A = never>() => Semigroup<A>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getFunctionSemigroup
getFunctionSemigroup
Use getSemigroup
instead.
Signature
export declare const getFunctionSemigroup: <S>(S: Semigroup<S>) => <A = never>() => Semigroup<(a: A) => S>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getIntercalateSemigroup
getIntercalateSemigroup
Use intercalate
instead.
Signature
export declare const getIntercalateSemigroup: <A>(middle: A) => (S: Semigroup<A>) => Semigroup<A>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getJoinSemigroup
getJoinSemigroup
Use max
instead.
Signature
export declare const getJoinSemigroup: <A>(O: Or.Ord<A>) => Semigroup<A>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getLastSemigroup
getLastSemigroup
Use last
instead.
Signature
export declare const getLastSemigroup: <A = never>() => Semigroup<A>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getMeetSemigroup
getMeetSemigroup
Use min
instead.
Signature
export declare const getMeetSemigroup: <A>(O: Or.Ord<A>) => Semigroup<A>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getObjectSemigroup
getObjectSemigroup
Use getAssignSemigroup
instead.
Signature
export declare const getObjectSemigroup: <A extends object = never>() => Semigroup<A>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getStructSemigroup
getStructSemigroup
Use struct
instead.
Signature
export declare const getStructSemigroup: <O extends ReadonlyRecord<string, any>>(semigroups: {
[K in keyof O]: Semigroup<O[K]>
}) => Semigroup<O>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
getTupleSemigroup
getTupleSemigroup
Use tuple
instead.
Signature
export declare const getTupleSemigroup: <T extends ReadonlyArray<Semigroup<any>>>(
...semigroups: T
) => Semigroup<{
[K in keyof T]: T[K] extends Semigroup<infer A> ? A : never
}>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
intercalate
Between each pair of elements insert middle
.
Signature
export declare const intercalate: <A>(middle: A) => (S: Semigroup<A>) => Semigroup<A>
Details
- Added in 0.1.0
Example
import { intercalate } from '@fp-tx/core/Semigroup'
import * as S from '@fp-tx/core/string'
import { pipe } from '@fp-tx/core/function'
const S1 = pipe(S.Semigroup, intercalate(' + '))
assert.strictEqual(S1.concat('a', 'b'), 'a + b')
License
- MIT – Copyright (c) 2017-present Giulio Canti
reverse
The dual of a Semigroup
, obtained by swapping the arguments of concat
.
Signature
export declare const reverse: <A>(S: Semigroup<A>) => Semigroup<A>
Details
- Added in 0.1.0
Example
import { reverse } from '@fp-tx/core/Semigroup'
import * as S from '@fp-tx/core/string'
assert.deepStrictEqual(reverse(S.Semigroup).concat('a', 'b'), 'ba')
License
- MIT – Copyright (c) 2017-present Giulio Canti
semigroupAll
semigroupAll
Use SemigroupAll
instead.
Signature
export declare const semigroupAll: Semigroup<boolean>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
semigroupAny
semigroupAny
Use SemigroupAny
instead.
Signature
export declare const semigroupAny: Semigroup<boolean>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
semigroupProduct
semigroupProduct
Use SemigroupProduct
instead.
Signature
export declare const semigroupProduct: Semigroup<number>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
semigroupString
semigroupString
Use Semigroup
instead.
Signature
export declare const semigroupString: Semigroup<string>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
semigroupSum
semigroupSum
Use SemigroupSum
instead.
Signature
export declare const semigroupSum: Semigroup<number>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
semigroupVoid
semigroupVoid
Use void
module instead.
Signature
export declare const semigroupVoid: Semigroup<void>
Details
- Added in 0.1.0
- Deprecated
License
- MIT – Copyright (c) 2017-present Giulio Canti
struct
Given a struct of semigroups returns a semigroup for the struct.
Signature
export declare const struct: <A>(semigroups: { [K in keyof A]: Semigroup<A[K]> }) => Semigroup<{
readonly [K_1 in keyof A]: A[K_1]
}>
Details
- Added in 0.1.0
Example
import { struct } from '@fp-tx/core/Semigroup'
import * as N from '@fp-tx/core/number'
interface Point {
readonly x: number
readonly y: number
}
const S = struct<Point>({
x: N.SemigroupSum,
y: N.SemigroupSum,
})
assert.deepStrictEqual(S.concat({ x: 1, y: 2 }, { x: 3, y: 4 }), { x: 4, y: 6 })
License
- MIT – Copyright (c) 2017-present Giulio Canti
tuple
Given a tuple of semigroups returns a semigroup for the tuple.
Signature
export declare const tuple: <A extends readonly unknown[]>(
...semigroups: { [K in keyof A]: Semigroup<A[K]> }
) => Semigroup<Readonly<A>>
Details
- Added in 0.1.0
Example
import { tuple } from '@fp-tx/core/Semigroup'
import * as B from '@fp-tx/core/boolean'
import * as N from '@fp-tx/core/number'
import * as S from '@fp-tx/core/string'
const S1 = tuple(S.Semigroup, N.SemigroupSum)
assert.deepStrictEqual(S1.concat(['a', 1], ['b', 2]), ['ab', 3])
const S2 = tuple(S.Semigroup, N.SemigroupSum, B.SemigroupAll)
assert.deepStrictEqual(S2.concat(['a', 1, true], ['b', 2, false]), ['ab', 3, false])
License
- MIT – Copyright (c) 2017-present Giulio Canti