Skip to content

Commit 40a70dc

Browse files
committed
version 0.4.0
1 parent 85a795a commit 40a70dc

37 files changed

+3726
-4018
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
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.4.0
17+
18+
- **Breaking Change**
19+
20+
- options
21+
- remove encoding (@gcanti)
22+
- remove matcheeName (@gcanti)
23+
- make generated `fold` always lazy and data-last (@gcanti)
24+
1625
# 0.3.1
1726

1827
- **Bug Fix**

README.md

Lines changed: 14 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,14 @@ export function some<A>(value0: A): Option<A> {
5252
5353
/** pattern matching */
5454
55-
// eager ---v
56-
export function fold<A, R>(fa: Option<A>, onNone: R, onSome: (value0: A) => R): R {
57-
switch (fa.type) {
58-
case 'None':
59-
return onNone
60-
case 'Some':
61-
return onSome(fa.value0)
62-
}
63-
}
64-
65-
// lazy ---v
66-
export function foldL<A, R>(fa: Option<A>, onNone: () => R, onSome: (value0: A) => R): R {
67-
switch (fa.type) {
68-
case 'None':
69-
return onNone()
70-
case 'Some':
71-
return onSome(fa.value0)
55+
export function fold<A, R>(onNone: () => R, onSome: (value0: A) => R): (fa: Option<A>) => R {
56+
return fa => {
57+
switch (fa.type) {
58+
case 'None':
59+
return onNone()
60+
case 'Some':
61+
return onSome(fa.value0)
62+
}
7263
}
7364
}
7465
@@ -84,11 +75,11 @@ export function _some<A>(): Prism<Option<A>, Option<A>> {
8475
return Prism.fromPredicate(s => s.type === 'Some')
8576
}
8677
87-
/** Setoid instance */
78+
/** Eq instance */
8879
89-
import { Setoid } from 'fp-ts/lib/Setoid'
80+
import { Eq } from 'fp-ts/lib/Eq'
9081
91-
export function getSetoid<A>(setoidSomeValue0: Setoid<A>): Setoid<Option<A>> {
82+
export function getEq<A>(eqSomeValue0: Eq<A>): Eq<Option<A>> {
9283
return {
9384
equals: (x, y) => {
9485
if (x === y) {
@@ -98,7 +89,7 @@ export function getSetoid<A>(setoidSomeValue0: Setoid<A>): Setoid<Option<A>> {
9889
return true
9990
}
10091
if (x.type === 'Some' && y.type === 'Some') {
101-
return setoidSomeValue0.equals(x.value0, y.value0)
92+
return eqSomeValue0.equals(x.value0, y.value0)
10293
}
10394
return false
10495
}
@@ -185,75 +176,6 @@ export type Constrained<A extends string> =
185176
}
186177
```
187178

188-
# `fp-ts` encoding
189-
190-
Example
191-
192-
Source
193-
194-
```haskell
195-
data Option A = None | Some A
196-
```
197-
198-
Output
199-
200-
```ts
201-
declare module 'fp-ts/lib/HKT' {
202-
interface URI2HKT<A> {
203-
Option: Option<A>
204-
}
205-
}
206-
207-
export const URI = 'Option'
208-
209-
export type URI = typeof URI
210-
211-
export type Option<A> = None<A> | Some<A>
212-
213-
export class None<A> {
214-
static value: Option<never> = new None()
215-
readonly _tag: 'None' = 'None'
216-
readonly _A!: A
217-
readonly _URI!: URI
218-
private constructor() {}
219-
fold<R>(onNone: R, _onSome: (value0: A) => R): R {
220-
return onNone
221-
}
222-
foldL<R>(onNone: () => R, _onSome: (value0: A) => R): R {
223-
return onNone()
224-
}
225-
}
226-
227-
export class Some<A> {
228-
readonly _tag: 'Some' = 'Some'
229-
readonly _A!: A
230-
readonly _URI!: URI
231-
constructor(readonly value0: A) {}
232-
fold<R>(_onNone: R, onSome: (value0: A) => R): R {
233-
return onSome(this.value0)
234-
}
235-
foldL<R>(_onNone: () => R, onSome: (value0: A) => R): R {
236-
return onSome(this.value0)
237-
}
238-
}
239-
240-
export const none: Option<never> = None.value
241-
242-
export function some<A>(value0: A): Option<A> {
243-
return new Some(value0)
244-
}
245-
246-
import { Prism } from 'monocle-ts'
247-
248-
export function _none<A>(): Prism<Option<A>, Option<A>> {
249-
return Prism.fromPredicate(s => s.type === 'None')
250-
}
251-
252-
export function _some<A>(): Prism<Option<A>, Option<A>> {
253-
return Prism.fromPredicate(s => s.type === 'Some')
254-
}
255-
```
256-
257179
# Options
258180

259181
```ts
@@ -264,22 +186,17 @@ export interface Options {
264186
tagName: string
265187
/** the name prefix used for pattern matching functions */
266188
foldName: string
267-
/** the name used for the input of pattern matching functions */
268-
matcheeName: string
269189
/**
270190
* the pattern matching handlers can be expressed as positional arguments
271191
* or a single object literal `tag -> handler`
272192
*/
273193
handlersStyle: { type: 'positional' } | { type: 'record'; handlersName: string }
274-
encoding: 'literal' | 'fp-ts'
275194
}
276195
277196
export const defaultOptions: Options = {
278-
tagName: 'type',
197+
tagName: '_tag',
279198
foldName: 'fold',
280-
matcheeName: 'fa',
281-
handlersStyle: { type: 'positional' },
282-
encoding: 'literal'
199+
handlersStyle: { type: 'positional' }
283200
}
284201
```
285202

@@ -295,7 +212,6 @@ lenses.tagName.set('tag')(defaultOptions)
295212
{
296213
tagName: 'tag',
297214
foldName: 'fold',
298-
matcheeName: 'fa',
299215
...
300216
}
301217
*/

docs/bundle.js

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

docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Home
3+
nav_order: 1
4+
---

docs/modules/ast.ts.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ parent: Modules
1414
- [lenses (constant)](#lenses-constant)
1515
- [constructors (function)](#constructors-function)
1616
- [data (function)](#data-function)
17-
- [folds (function)](#folds-function)
17+
- [eq (function)](#eq-function)
18+
- [fold (function)](#fold-function)
1819
- [prisms (function)](#prisms-function)
19-
- [setoid (function)](#setoid-function)
2020

2121
---
2222

@@ -25,9 +25,11 @@ parent: Modules
2525
**Signature**
2626

2727
```ts
28-
export interface AST<A> extends Reader<Options, A> {}
28+
export interface AST<A> extends R.Reader<Options, A> {}
2929
```
3030

31+
Added in v0.4.0
32+
3133
# Options (interface)
3234

3335
**Signature**
@@ -38,17 +40,16 @@ export interface Options {
3840
tagName: string
3941
/** the name prefix used for pattern matching functions */
4042
foldName: string
41-
/** the name used for the input of pattern matching functions */
42-
matcheeName: string
4343
/**
4444
* the pattern matching handlers can be expressed as positional arguments
4545
* or a single object literal `tag -> handler`
4646
*/
4747
handlersStyle: { type: 'positional' } | { type: 'record'; handlersName: string }
48-
encoding: 'literal' | 'fp-ts'
4948
}
5049
```
5150

51+
Added in v0.4.0
52+
5253
# defaultOptions (constant)
5354

5455
**Signature**
@@ -57,6 +58,8 @@ export interface Options {
5758
export const defaultOptions: Options = ...
5859
```
5960

61+
Added in v0.4.0
62+
6063
# lenses (constant)
6164

6265
**Signature**
@@ -65,42 +68,54 @@ export const defaultOptions: Options = ...
6568
export const lenses: { [K in keyof Options]: Lens<Options, Options[K]> } = ...
6669
```
6770

71+
Added in v0.4.0
72+
6873
# constructors (function)
6974

7075
**Signature**
7176

7277
```ts
73-
export const constructors = (d: M.Data): AST<Array<ts.Node>> => ...
78+
export function constructors(d: M.Data): AST<Array<ts.Node>> { ... }
7479
```
7580

81+
Added in v0.4.0
82+
7683
# data (function)
7784

7885
**Signature**
7986

8087
```ts
81-
export const data = (d: M.Data): AST<Array<ts.Node>> => ...
88+
export function data(d: M.Data): AST<Array<ts.Node>> { ... }
8289
```
8390

84-
# folds (function)
91+
Added in v0.4.0
92+
93+
# eq (function)
8594

8695
**Signature**
8796

8897
```ts
89-
export const folds = (d: M.Data): AST<Array<ts.FunctionDeclaration>> => ...
98+
export function eq(d: M.Data): AST<Array<ts.Node>> { ... }
9099
```
91100

92-
# prisms (function)
101+
Added in v0.4.0
102+
103+
# fold (function)
93104

94105
**Signature**
95106

96107
```ts
97-
export const prisms = (d: M.Data): AST<Array<ts.Node>> => ...
108+
export function fold(d: M.Data): AST<O.Option<ts.FunctionDeclaration>> { ... }
98109
```
99110

100-
# setoid (function)
111+
Added in v0.4.0
112+
113+
# prisms (function)
101114

102115
**Signature**
103116

104117
```ts
105-
export const setoid = (d: M.Data): AST<Array<ts.Node>> => ...
118+
export function prisms(d: M.Data): AST<Array<ts.Node>> { ... }
106119
```
120+
121+
Added in v0.4.0

0 commit comments

Comments
 (0)