forked from gcanti/fp-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.ts
44 lines (28 loc) · 1.06 KB
/
5.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Code for http://www.tomharding.me/2017/03/21/fantas-eel-and-specification-5/
//
import { getFirstMonoid, none, some } from '../src/Option'
import { monoidSum } from '../src/Monoid'
const firstMonoid = getFirstMonoid<number>()
console.log(firstMonoid.concat(none, some(1)))
// => some(1)
console.log(firstMonoid.concat(some(1), some(2)))
// => some(1)
import { fold } from '../src/Monoid'
const sumAll = fold(monoidSum)
console.log(sumAll([1, 2, 3, 4, 5]))
// => 15
console.log(sumAll([]))
// => 0
import { getMonoid } from '../src/Tuple'
import { monoidString } from '../src/Monoid'
const monoidTuple = getMonoid(monoidSum, monoidString)
console.log(monoidTuple.empty)
// => new Tuple([0, ""])
import { getFunctionMonoid, monoidAll } from '../src/Monoid'
export const monoidFunction = getFunctionMonoid(monoidAll)<string>()
export const gt2 = (s: string) => s.length > 2
export const lt4 = (s: string) => s.length < 4
export const between2and4 = monoidFunction.concat(gt2, lt4)
console.log(between2and4('foo')) // => true
console.log(between2and4('')) // => false