Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Commit

Permalink
feat: rename Reader.flatMap to chain
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed May 3, 2020
1 parent 9ba402c commit ae5c409
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/monads/Reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const contramap = <A, B, C>(cToA: (c: C) => A) => (
reader: Reader<A, B>,
): Reader<C, B> => pipe(cToA, reader)

export const flatMap = <A, B, C>(bToReaderAC: (b: B) => Reader<A, C>) => (
export const chain = <A, B, C>(bToReaderAC: (b: B) => Reader<A, C>) => (
reader: Reader<A, B>,
): Reader<A, C> => (a: A) => bToReaderAC(reader(a))(a)
6 changes: 3 additions & 3 deletions src/monads/__tests__/Reader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Reader, map, flatMap, contramap } from "../Reader"
import { Reader, map, chain, contramap } from "../Reader"
import { pipe, pluck } from "../../core"

type DB = string
Expand Down Expand Up @@ -46,8 +46,8 @@ describe("Reader", () => {
).toEqual({ id: "123", name: "Thomas", db: "other" })
})

test("flatMap", () => {
const getAndSaveUser = pipe(getUser, flatMap(saveUser))
test("chain", () => {
const getAndSaveUser = pipe(getUser, chain(saveUser))
expect(getAndSaveUser("123")(DB)).toEqual({
id: "123",
name: "Thomas",
Expand Down

0 comments on commit ae5c409

Please sign in to comment.