Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

Commit b12e4f2

Browse files
committed
prepare first release, ref #21
1 parent 74df99e commit b12e4f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+204
-223
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"presets": ["es2015"],
2+
"presets": ["es2015", "react"],
33
"plugins" : [
44
"syntax-flow",
55
"transform-flow-strip-types",

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.log
2-
node_modules
32
dev
3+
lib
4+
node_modules

.npmignore

-5
This file was deleted.

CHANGELOG.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
> **Tags:**
4+
> - [New Feature]
5+
> - [Bug Fix]
6+
> - [Breaking Change]
7+
> - [Documentation]
8+
> - [Internal]
9+
> - [Polish]
10+
> - [Experimental]
11+
12+
**Note**: Gaps between patch versions are faulty/broken releases.
13+
**Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.
14+
15+
## 0.1.0
16+
17+
Initial release

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Giulio Canti
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+20-68
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,15 @@
22

33
- statically type checked by [Flow](https://flowtype.org/)
44
- PureScript-like standard library
5-
- static land compatible ([Specification](https://github.com/rpominov/static-land))
5+
- [static land](https://github.com/rpominov/static-land) compatible
66

77
The idea (faking higher kinded types in Flow) is based on the paper [Lightweight higher-kinded polymorphism](https://www.cl.cam.ac.uk/~jdy22/papers/lightweight-higher-kinded-polymorphism.pdf) and [elm-brands](https://github.com/joneshf/elm-brands).
88

9-
# Try it out
10-
11-
```
12-
git clone https://github.com/gcanti/flow-static-land.git
13-
cd flow-static-land
14-
npm install
15-
npm start
16-
17-
# execute ./node_modules/.bin/babel-node playground/index.js
18-
# or open the page playground/index.html in a browser
19-
# then edit playground/index.js
20-
```
21-
22-
# Examples
23-
24-
Real world examples
25-
26-
- a Signal library ([purescript-signal](https://github.com/bodil/purescript-signal) porting)
27-
- a QuickCheck library ([purescript-quickcheck](https://github.com/purescript/purescript-quickcheck) partial porting)
28-
29-
## `Maybe` and `Arr`
9+
# Example
3010

3111
```js
32-
import * as maybe from 'flow-static-land/Maybe'
33-
import * as arr from 'flow-static-land/Arr'
12+
import * as maybe from 'flow-static-land/lib/Maybe'
13+
import * as arr from 'flow-static-land/lib/Arr'
3414

3515
const f = (n) => n * 2
3616
const g = (n) => n + 1
@@ -63,47 +43,28 @@ const f = (n) => n * 2
6343
^^^^^ number
6444
```
6545

66-
## Expressing side effects with the `Eff` monad
46+
# Related blog posts
6747

68-
See this [blog post](https://medium.com/@gcanti/the-eff-monad-implemented-in-flow-40803670c3eb#.sj4m00hpe) for context
69-
70-
```js
71-
import type { Eff } from 'flow-static-land/Eff'
72-
import { inj } from 'flow-static-land/Eff'
48+
- [Higher kinded types with Flow](https://medium.com/@gcanti/higher-kinded-types-in-flow-275b657992b7)
49+
- [Expressing side effects with the `Eff` monad](https://medium.com/@gcanti/the-eff-monad-implemented-in-flow-40803670c3eb)
50+
- [Phantom types with Flow](https://medium.com/@gcanti/phantom-types-with-flow-828aff73232b)
51+
- [Refinements with Flow](https://medium.com/@gcanti/refinements-with-flow-9c7eeae8478b)
7352

74-
class DB {}
53+
# More examples
7554

76-
type User = {
77-
username: string,
78-
uid: number
79-
};
80-
81-
const users = {}
82-
let uid = 0
83-
84-
function createUser(username: string): Eff<{ write: DB }, User> {
85-
return inj(() => {
86-
users[username] = { username, uid: ++uid }
87-
return users[username]
88-
})
89-
}
55+
`examples` directory:
9056

91-
function lookupUser(username: string): Eff<{ read: DB }, ?User> {
92-
return inj(() => users[username])
93-
}
94-
95-
// the signature shows that createThenLookupUser will read and write to the db
96-
const createThenLookupUser: (username: string) => Eff<{ read: DB, write: DB }, ?User> =
97-
username => chain(user => lookupUser(user.username), createUser(username))
98-
```
57+
- a Signal library ([purescript-signal](https://github.com/bodil/purescript-signal) porting)
58+
- a QuickCheck library ([purescript-quickcheck](https://github.com/purescript/purescript-quickcheck) partial porting)
59+
- a React library (experimental)
9960

10061
# Setup
10162

102-
Download the source code with the command `npm i gcanti/flow-static-land#master`
103-
104-
**Bundles**
63+
```sh
64+
npm install flow-static-land --save
65+
```
10566

106-
In order to build a bundle, add the following plugins to your `.babelrc` file
67+
Babel config
10768

10869
```
10970
{
@@ -116,15 +77,6 @@ In order to build a bundle, add the following plugins to your `.babelrc` file
11677
}
11778
```
11879

119-
For webpack, add the following include to your babel loader
120-
121-
```js
122-
{
123-
loader: 'babel',
124-
include: [
125-
path.resolve(__dirname, "node_modules/flow-static-land"),
126-
path.resolve(__dirname, "path/to/your/code")
127-
]
128-
}
129-
```
80+
# License
13081

82+
The MIT License (MIT)

QuickCheck.js renamed to examples/QuickCheck.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
77
*/
88

9-
import type { Eff } from './Eff'
10-
import * as eff from './Eff'
11-
import { CONSOLE } from './Console'
12-
import { RANDOM, random } from './Random'
13-
import { EXCEPTION, throwException, error } from './Exception'
14-
import type { State } from './State'
15-
import * as state from './State'
16-
import type { Arr } from './Arr'
17-
import * as arr from './Arr'
18-
import { log } from './Console'
19-
import type { Either } from './Either'
20-
import * as either from './Either'
21-
import { replicateA } from './Unfoldable'
22-
import * as tuple from './Tuple'
9+
import type { Eff } from '../src/Eff'
10+
import * as eff from '../src/Eff'
11+
import { CONSOLE } from '../src/Console'
12+
import { RANDOM, random } from '../src/Random'
13+
import { EXCEPTION, throwException, error } from '../src/Exception'
14+
import type { State } from '../src/State'
15+
import * as state from '../src/State'
16+
import type { Arr } from '../src/Arr'
17+
import * as arr from '../src/Arr'
18+
import { log } from '../src/Console'
19+
import type { Either } from '../src/Either'
20+
import * as either from '../src/Either'
21+
import { replicateA } from '../src/Unfoldable'
22+
import * as tuple from '../src/Tuple'
2323

2424
/*
2525

React.js renamed to examples/React.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// @flow
2-
import { HKT } from './HKT'
3-
import type { Contravariant } from './Contravariant'
4-
import type { Arr } from './Arr'
5-
import * as arr from './Arr'
2+
import { HKT } from '../src/HKT'
3+
import type { Contravariant } from '../src/Contravariant'
4+
import type { Arr } from '../src/Arr'
5+
import * as arr from '../src/Arr'
66
import React from 'react'
77

88
class IsReactComponent {}

Signal.js renamed to examples/Signal.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
77
*/
88

9-
import type { Applicative } from './Applicative'
10-
import type { Functor } from './Functor'
11-
import type { Semigroup } from './Semigroup'
12-
import type { Foldable } from './Foldable'
13-
import type { Maybe } from './Maybe'
14-
import type { Setoid } from './Setoid'
15-
import type { Predicate } from './Fun'
16-
17-
import { HKT } from './HKT'
18-
import * as maybe from './Maybe'
9+
import type { Applicative } from '../src/Applicative'
10+
import type { Functor } from '../src/Functor'
11+
import type { Semigroup } from '../src/Semigroup'
12+
import type { Foldable } from '../src/Foldable'
13+
import type { Maybe } from '../src/Maybe'
14+
import type { Setoid } from '../src/Setoid'
15+
import type { Predicate } from '../src/Fun'
16+
17+
import { HKT } from '../src/HKT'
18+
import * as maybe from '../src/Maybe'
1919

2020
class IsSignal {}
2121

exercises/answer1.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3-
import type { Ord } from '../Ord'
4-
import { numberOrd, stringOrd } from '../Ord'
3+
import type { Ord } from '../src/Ord'
4+
import { numberOrd, stringOrd } from '../src/Ord'
55

66
export function binarySearch<A>(xs: Array<A>, x: A, ord: Ord<A>): number {
77
function go(low: number, mid: number, high: number): number {

exercises/answer2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3-
import type { Ord } from '../Ord'
4-
import { greaterThan, numberOrd } from '../Ord'
3+
import type { Ord } from '../src/Ord'
4+
import { greaterThan, numberOrd } from '../src/Ord'
55

66
export function isSorted<A>(xs: Array<A>, ord: Ord<A>): boolean {
77
const len = xs.length

exercises/answer3.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3-
import { HKT } from '../HKT'
4-
import type { Functor } from '../Functor'
3+
import { HKT } from '../src/HKT'
4+
import type { Functor } from '../src/Functor'
55

66
class IsList {}
77

exercises/answer4.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

3-
import type { Maybe } from '../Maybe'
4-
import * as maybe from '../Maybe'
3+
import type { Maybe } from '../src/Maybe'
4+
import * as maybe from '../src/Maybe'
55

66
export function head<A>(xs: Array<A>): Maybe<A> {
77
if (xs.length) {
@@ -13,8 +13,8 @@ export function head<A>(xs: Array<A>): Maybe<A> {
1313
console.log(head([1, 2, 3])) // => 1
1414
console.log(head([])) // => null
1515

16-
import type { Either } from '../Either'
17-
import * as either from '../Either'
16+
import type { Either } from '../src/Either'
17+
import * as either from '../src/Either'
1818

1919
export function elementAt<A>(xs: Array<A>, i: number): Either<string, A> {
2020
if (i < 0) {

exercises/answer5.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @flow
22

3-
import type { Maybe } from '../Maybe'
4-
import * as maybe from '../Maybe'
3+
import type { Maybe } from '../src/Maybe'
4+
import * as maybe from '../src/Maybe'
55

6-
import type { Arr } from '../Arr'
7-
import * as arr from '../Arr'
6+
import type { Arr } from '../src/Arr'
7+
import * as arr from '../src/Arr'
88

99
export function getAllJustsOrNothing<A>(xs: Arr<Maybe<A>>): Maybe<Arr<A>> {
1010
return arr.sequence(maybe, xs)

exercises/answer6.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @flow
22

3-
import type { Arr } from '../Arr'
4-
import * as arr from '../Arr'
5-
import * as maybe from '../Maybe'
6-
import * as tuple from '../Tuple'
3+
import type { Arr } from '../src/Arr'
4+
import * as arr from '../src/Arr'
5+
import * as maybe from '../src/Maybe'
6+
import * as tuple from '../src/Tuple'
77

88
export function evens(count: number): Arr<number> {
99
return arr.unfoldr(n => {

exercises/exercise2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
*/
1010

11-
import type { Ord } from '../Ord'
11+
import type { Ord } from '../src/Ord'
1212

1313
export function isSorted<A>(xs: Array<A>, ord: Ord<A>): boolean {
1414
throw 'not implemented'

exercises/exercise4.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Write a type safe head function.
88
99
*/
10-
import type { Maybe } from '../Maybe'
10+
import type { Maybe } from '../src/Maybe'
1111

1212
export function head<A>(xs: Array<A>): Maybe<A> {
1313
throw 'not implemented'
@@ -18,7 +18,7 @@ export function head<A>(xs: Array<A>): Maybe<A> {
1818
Write a type safe elementAt function
1919
2020
*/
21-
import type { Either } from '../Either'
21+
import type { Either } from '../src/Either'
2222

2323
export function elementAt<A>(xs: Array<A>, i: number): Either<string, A> {
2424
throw 'not implemented'

exercises/exercise5.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
Just with a list of all the values
1111
1212
*/
13-
import type { Arr } from '../Arr'
14-
import type { Maybe } from '../Maybe'
13+
import type { Arr } from '../src/Arr'
14+
import type { Maybe } from '../src/Maybe'
1515

1616
export function getAllJustsOrNothing<A>(xs: Arr<Maybe<A>>): Maybe<Arr<A>> {
1717
throw 'not implemented'

exercises/exercise6.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Hint: use arr.unfoldr
1010
1111
*/
12-
import type { Arr } from '../Arr'
12+
import type { Arr } from '../src/Arr'
1313

1414
export function evens(count: number): Arr<number> {
1515
throw 'not implemented'

0 commit comments

Comments
 (0)