Skip to content

Commit 4901787

Browse files
committed
New Feature: generate prisms, closes #10
1 parent e37214a commit 4901787

File tree

15 files changed

+197
-12
lines changed

15 files changed

+197
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
**Note**: Gaps between patch versions are faulty/broken releases.
1414
**Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.
1515

16+
# 0.2.1
17+
18+
- **New Feature**
19+
- generate prisms, closes #10 (@gcanti)
20+
1621
# 0.2.0
1722

1823
- **Breaking Change**

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ export function foldL<A, R>(fa: Option<A>, onNone: () => R, onSome: (value0: A)
7171
return onSome(fa.value0)
7272
}
7373
}
74+
75+
/** prisms */
76+
77+
import { Prism } from 'monocle-ts'
78+
79+
export function _none<A>(): Prism<Option<A>, Option<A>> {
80+
return Prism.fromPredicate(s => s.type === 'None')
81+
}
82+
83+
export function _some<A>(): Prism<Option<A>, Option<A>> {
84+
return Prism.fromPredicate(s => s.type === 'Some')
85+
}
7486
```
7587

7688
# Records
@@ -209,6 +221,16 @@ export const none: Option<never> = None.value
209221
export function some<A>(value0: A): Option<A> {
210222
return new Some(value0)
211223
}
224+
225+
import { Prism } from 'monocle-ts'
226+
227+
export function _none<A>(): Prism<Option<A>, Option<A>> {
228+
return Prism.fromPredicate(s => s.type === 'None')
229+
}
230+
231+
export function _some<A>(): Prism<Option<A>, Option<A>> {
232+
return Prism.fromPredicate(s => s.type === 'Some')
233+
}
212234
```
213235

214236
# Options

docs/bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Constrained.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ export function foldL<A extends string, R>(fa: Constrained<A>, onFetching: () =>
1919
case "GotData": return onGotData(fa.value0);
2020
} }
2121

22+
import { Prism } from "monocle-ts";
23+
24+
export function _fetching<A extends string>(): Prism<Constrained<A>, Constrained<A>> { return Prism.fromPredicate(s => s.type === "Fetching"); }
25+
26+
export function _gotData<A extends string>(): Prism<Constrained<A>, Constrained<A>> { return Prism.fromPredicate(s => s.type === "GotData"); }
27+

examples/Either.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ export function fold<L, R, R1>(fa: Either<L, R>, onLeft: (value0: L) => R1, onRi
1515
case "Right": return onRight(fa.value0);
1616
} }
1717

18+
import { Prism } from "monocle-ts";
19+
20+
export function _left<L, R>(): Prism<Either<L, R>, Either<L, R>> { return Prism.fromPredicate(s => s.type === "Left"); }
21+
22+
export function _right<L, R>(): Prism<Either<L, R>, Either<L, R>> { return Prism.fromPredicate(s => s.type === "Right"); }
23+

examples/FooBar.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ export function foldL<R>(fa: FooBar, onFoo: () => R, onBar: () => R): R { switch
1818
case "Bar": return onBar();
1919
} }
2020

21+
import { Prism } from "monocle-ts";
22+
23+
export const _Foo: Prism<FooBar, FooBar> = Prism.fromPredicate(s => s.type === "Foo");
24+
25+
export const _Bar: Prism<FooBar, FooBar> = Prism.fromPredicate(s => s.type === "Bar");
26+

examples/Maybe.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ export function foldL<A, R>(fa: Maybe<A>, onNothing: () => R, onJust: (value: A)
1919
case "Just": return onJust(fa.value);
2020
} }
2121

22+
import { Prism } from "monocle-ts";
23+
24+
export function _nothing<A>(): Prism<Maybe<A>, Maybe<A>> { return Prism.fromPredicate(s => s.type === "Nothing"); }
25+
26+
export function _just<A>(): Prism<Maybe<A>, Maybe<A>> { return Prism.fromPredicate(s => s.type === "Just"); }
27+

examples/Option.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ export function foldL<A, R>(fa: Option<A>, onNone: () => R, onSome: (value0: A)
1919
case "Some": return onSome(fa.value0);
2020
} }
2121

22+
import { Prism } from "monocle-ts";
23+
24+
export function _none<A>(): Prism<Option<A>, Option<A>> { return Prism.fromPredicate(s => s.type === "None"); }
25+
26+
export function _some<A>(): Prism<Option<A>, Option<A>> { return Prism.fromPredicate(s => s.type === "Some"); }
27+

examples/Tree.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ export function foldL<A, R>(fa: Tree<A>, onLeaf: () => R, onNode: (value0: Tree<
2121
case "Node": return onNode(fa.value0, fa.value1, fa.value2);
2222
} }
2323

24+
import { Prism } from "monocle-ts";
25+
26+
export function _leaf<A>(): Prism<Tree<A>, Tree<A>> { return Prism.fromPredicate(s => s.type === "Leaf"); }
27+
28+
export function _node<A>(): Prism<Tree<A>, Tree<A>> { return Prism.fromPredicate(s => s.type === "Node"); }
29+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fp-ts-codegen",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "TypeScript code generation from a haskell-like syntax for ADT",
55
"files": [
66
"lib"

0 commit comments

Comments
 (0)