Skip to content

Commit

Permalink
feat: Remove onPure
Browse files Browse the repository at this point in the history
  • Loading branch information
edahlseng committed Jul 14, 2019
1 parent d946609 commit c9b0c06
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 16 deletions.
4 changes: 1 addition & 3 deletions documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ interpreter :: (a -> Eff b c, effect -> boolean, effect -> (d -> void) -> void)
```flow
type Interpreter<effect> = ({interpreterCotinuation: Interpreter<any>, interpreterRestart: Interpreter<any>}) => Eff<any, any> => void;

declare function interpreter<a, b, c, d, effect>({ onPure: a => Eff<b, c>, predicate: (effect) => boolean, handler: (effect) => (d => void) => void}) => Interpreter effect
declare function interpreter<a, b, c, d, effect>({ predicate: (effect) => boolean, handler: (effect) => (d => void) => void}) => Interpreter effect
```

Example:
Expand All @@ -201,7 +201,6 @@ Example:
import { interpreter, map, pure, send } from 'eff';

const randomNumberInterpreter = interpreter({
onPure: pure,
predicate: x => x.type === 'random-number',
handler: effect => continuation => continuation(Math.random()),
})
Expand Down Expand Up @@ -229,7 +228,6 @@ import { chain, interpreter, pure, run, send } from 'eff';
const application = chain(value => pure(value * 2))(send({ type: 'random-number' }));

const randomNumberInterpreter = interpreter({
onPure: pure,
predicate: x => x.type === 'random-number',
handler: effect => continuation => continuation(Math.random()),
})
Expand Down
4 changes: 1 addition & 3 deletions sources/eff.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ export const run = (...interpreters: Array<Function>) => (
export const send = (t: any) => Eff.Impure(t, Eff.Pure);

export const interpreter = ({
onPure,
predicate,
handler,
}: {
onPure: Function,
predicate: Function,
handler: Function,
}) => ({
Expand All @@ -106,7 +104,7 @@ export const interpreter = ({
interpreterRestart: Function,
}) => (m: EffMonad) =>
m.cata({
Pure: x => interpreterContinuation(onPure(x)),
Pure: x => interpreterContinuation(Eff.Pure(x)),
Impure: (effect, continuation) =>
predicate(effect)
? handler(effect)(
Expand Down
3 changes: 1 addition & 2 deletions sources/fileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { taggedSum } from "daggy";
import fs from "fs";
import path from "path";

import Eff, { interpreter, send } from "./eff";
import { interpreter, send } from "./eff";

const FileSystem = taggedSum("FileSystem", {
readFile: ["path"],
Expand All @@ -19,7 +19,6 @@ export const writeFile = (

export const interpretLocalFileSystem = (fileSystemRoot: string) =>
interpreter({
onPure: x => Eff.Pure(x),
predicate: x => FileSystem.is(x),
handler: fileSystemEffect =>
fileSystemEffect.cata({
Expand Down
3 changes: 1 addition & 2 deletions sources/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
anyPass,
} from "ramda";

import Eff, { interpreter, send } from "./eff.js";
import { interpreter, send } from "./eff.js";

const Input = daggy.taggedSum("Input", {
getCharacter: [],
Expand Down Expand Up @@ -119,7 +119,6 @@ export const interpretInput = (
inputStream: stream$Readable & { +setRawMode?: boolean => void },
) =>
interpreter({
onPure: Eff.Pure,
predicate: x => Input.is(x),
handler: inputEffect =>
inputEffect.cata({
Expand Down
3 changes: 1 addition & 2 deletions sources/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import daggy from "daggy";

import Eff, { interpreter, send } from "./eff.js";
import { interpreter, send } from "./eff.js";

const Output = daggy.taggedSum("Output", {
putString: ["string"],
Expand All @@ -13,7 +13,6 @@ export const putStringLine = (s: string) => send(Output.putString(s + "\n"));

export const interpretOutput = (outputStream: stream$Writable) =>
interpreter({
onPure: Eff.Pure,
predicate: x => Output.is(x),
handler: outputEffect =>
outputEffect.cata({
Expand Down
3 changes: 1 addition & 2 deletions sources/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import daggy from "daggy";

import Eff, { interpreter, send } from "./eff.js";
import { interpreter, send } from "./eff.js";

const Reader = daggy.taggedSum("Reader", {
get: [],
Expand All @@ -12,7 +12,6 @@ export const get = () => send(Reader.get);

export const interpretReader = (i: any) =>
interpreter({
onPure: Eff.Pure,
predicate: x => Reader.is(x),
handler: readerEffect =>
readerEffect.cata({
Expand Down
3 changes: 1 addition & 2 deletions sources/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import daggy from "daggy";

import Eff, { interpreter, send } from "./eff.js";
import { interpreter, send } from "./eff.js";

const State = daggy.taggedSum("State", {
get: [],
Expand All @@ -19,7 +19,6 @@ export const interpretState = (startingState: mixed) => {
let state = startingState;

return interpreter({
onPure: Eff.Pure,
predicate: x => State.is(x),
handler: stateEffect =>
stateEffect.cata({
Expand Down

0 comments on commit c9b0c06

Please sign in to comment.