Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
feat: added many law tests and format datum_either
Browse files Browse the repository at this point in the history
Still don't have test completion for the laws around
the various static-land algebras. Also, I think it might be
necessary to change the interface of the asserts to take the
various type instances instead of generating them. This will
allow testing additional edge cases.
  • Loading branch information
baetheus committed Oct 8, 2020
1 parent 3e997c9 commit dfd55c5
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 17 deletions.
4 changes: 4 additions & 0 deletions array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const Monad = D.createMonad<ReadonlyArray<_>>({
chain: (fatb, ta) => _map(ta, (b) => fatb(b)).flat(1),
});

export const Filterable: TC.Filterable<ReadonlyArray<_>> = {
filter: (predicate, ta) => ta.filter(predicate),
};

export const Apply: TC.Apply<ReadonlyArray<_>> = {
ap: Monad.ap,
map: Functor.map,
Expand Down
10 changes: 10 additions & 0 deletions datum_either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,25 @@ export type DatumEither<E, A> = DA.Datum<E.Either<E, A>>;
**************************************************************************************************/

export const initial: Initial = DA.initial;

export const pending: Pending = DA.pending;

export const refresh = <E = never, A = never>(
value: E.Either<E, A>,
): DatumEither<E, A> => DA.refresh(value);

export const replete = <E = never, A = never>(
value: E.Either<E, A>,
): DatumEither<E, A> => DA.replete(value);

export const success = <E = never, A = never>(a: A): DatumEither<E, A> =>
replete(E.right(a));

export const failure = <E = never, A = never>(e: E): DatumEither<E, A> =>
replete(E.left(e));

export const constInitial = () => initial;

export const constPending = () => pending;

export const fromNullable = <E, A>(a: A): DatumEither<E, NonNullable<A>> =>
Expand All @@ -65,20 +70,25 @@ export const tryCatch = <E, A>(

export const isInitial = <E, A>(m: DatumEither<E, A>): m is Initial =>
m.tag === "Initial";

export const isPending = <E, A>(m: DatumEither<E, A>): m is Pending =>
m.tag === "Pending";

export const isRefresh = <E, A>(m: DatumEither<E, A>): m is Refresh<E, A> =>
m.tag === "Refresh";

export const isReplete = <E, A>(m: DatumEither<E, A>): m is Replete<E, A> =>
m.tag === "Replete";

export const isNone = <E, A>(m: DatumEither<E, A>): m is None =>
isInitial(m) || isPending(m);

export const isSome = <E, A>(m: DatumEither<E, A>): m is Some<E, A> =>
isRefresh(m) || isReplete(m);

export const isSuccess = <E, A>(m: DatumEither<E, A>): m is Success<A> =>
isSome(m) && E.isRight(m.value);

export const isFailure = <E, A>(m: DatumEither<E, A>): m is Failure<E> =>
isSome(m) && E.isLeft(m.value);

Expand Down
6 changes: 3 additions & 3 deletions testing/array.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { assertMonad } from "./assert.ts";
import * as T from "./assert.ts";

import * as A from "../array.ts";

Deno.test({
name: "Array Modules",
async fn() {
// Test Laws
await assertMonad(A.Monad, "Array");
await T.assertMonad(A.Monad, "Array");
T.assertFilterable(A.Filterable, A.of, "Array");
},
});

0 comments on commit dfd55c5

Please sign in to comment.