Skip to content

Commit

Permalink
add getFunctionSemigroup
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Feb 12, 2018
1 parent 64a4a06 commit 18bd8f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"typings": "lib/index.d.ts",
"scripts": {
"lint": "tslint src/**/*.ts test/**/*.ts examples/**/*.ts exercises/**/*.ts",
"mocha": "mocha -r ts-node/register test/*.ts",
"mocha": "TS_NODE_CACHE=false mocha -r ts-node/register test/*.ts",
"prettier":
"prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test,examples,exercises}/**/*.ts\"",
"fix-prettier":
Expand Down
5 changes: 3 additions & 2 deletions src/Monoid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
semigroupSum,
semigroupAny,
getArraySemigroup,
semigroupVoid
semigroupVoid,
getFunctionSemigroup
} from './Semigroup'
import { Endomorphism, identity, compose } from './function'

Expand Down Expand Up @@ -105,7 +106,7 @@ export const monoidVoid: Monoid<void> = {
/** @function */
export const getFunctionMonoid = <M>(M: Monoid<M>) => <A = never>(): Monoid<(a: A) => M> => {
return {
concat: (f, g) => a => M.concat(f(a), g(a)),
...getFunctionSemigroup(M)<A>(),
empty: () => M.empty
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/Semigroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export const getDualSemigroup = <A>(S: Semigroup<A>): Semigroup<A> => {
}
}

/** @function */
export const getFunctionSemigroup = <S>(S: Semigroup<S>) => <A = never>(): Semigroup<(a: A) => S> => {
return {
concat: (f, g) => a => S.concat(f(a), g(a))
}
}

/** @function */
export const getRecordSemigroup = <O extends { [key: string]: any }>(
semigroups: { [K in keyof O]: Semigroup<O[K]> }
Expand Down

0 comments on commit 18bd8f8

Please sign in to comment.