-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmonoid.ts
66 lines (49 loc) · 2.16 KB
/
monoid.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as M from 'fp-ts/Monoid'
import * as B from 'fp-ts/Bounded'
import { flow } from 'fp-ts/function'
import * as Arr from 'fp-ts/Array'
import * as O from 'fp-ts/Option'
// A Monoid describes a way of combining values
// A Monoid<number> could describe adding two numbers, or multiplying them
// add up all the passed numbers
export const one: (as: number[]) => number = undefined as any
// multiply all the passed numbers
export const two: (as: number[]) => number = undefined as any
// combine all passed strings together
export const three: (as: string[]) => string = undefined as any
// return true if any of the provided values are true
export const four: (as: boolean[]) => boolean = undefined as any
// return true if all of the provided values are true
export const five: (as: boolean[]) => boolean = undefined as any
type Coord = { x: number; y: number }
// combine an array of co-ordinate points by adding
export const six: (points: Coord[]) => Coord = undefined as any
// get the largest number in an array of numbers
export const seven: (as: number[]) => number = undefined as any
// get the smallest number in an array of numbers
export const eight: (as: number[]) => number = undefined as any
// the range is the minimum and maximum number in a set
type Range = [number, number]
// get the range for an array of numbers
export const nine: (as: number[]) => Range = undefined as any
// given a list of Option values, return the first Some
export const ten: <A>(
as: O.Option<A>[]
) => O.Option<A> = undefined as any
type Person = {
name: string
age: number
}
const lastMonoid: M.Monoid<string> = undefined as any
// given a list of Option<Person>, combine all Somes by adding the ages and
// keeping the last name
// you will need to make your own Monoid<string> to help
export const eleven: (
people: O.Option<Person>[]
) => O.Option<Person> = undefined as any
// given an array of predicates (that take a number and return a boolean)
// combine them into one predicate that, given one number, returns true if all the
// predicates pass, and false otherwise
export const twelve: (
predicates: ((a: number) => boolean)[]
) => (a: number) => boolean = undefined as any