Skip to content

Commit

Permalink
Reorganize files structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mobily committed Nov 28, 2021
1 parent 3e8ca16 commit 94ca40a
Show file tree
Hide file tree
Showing 166 changed files with 10,127 additions and 6,517 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<strong>Belt (<code>ReScript</code>) implementation in TypeScript.</strong>
</p>

## Motivation

I pretty much like ReScript, its features, tooling are great developer experience (as well as `Belt` stdlib). I wish it was my main tool on a daily basis work. Unfortunately it isn't, since most of the commercial projects I have been working on recently are built with TypeScript, which at this point is fully understandable from the business perspective.

## Features

- better type inference because of the `data-first` implementation
Expand Down
6 changes: 3 additions & 3 deletions __tests__/Array/drop.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { A } from '../..'

describe('drop', () => {
it('should return the same values as the provided array', () => {
it('returns the same values as the provided array', () => {
expect(A.drop([1, 2, 3], -1)).toEqual([1, 2, 3])
})

it('should return an empty array', () => {
it('returns an empty array', () => {
expect(A.drop([1, 2, 3], 4)).toEqual([])
expect(A.drop([1, 2, 3], 3)).toEqual([])
})

it('should return a new array that does not contain the first `n` items', () => {
it('returns a new array that does not contain the first `n` items', () => {
expect(A.drop([], 0)).toEqual([])
expect(A.drop([1, 2, 3], 0)).toEqual([1, 2, 3])
expect(A.drop([1], 1)).toEqual([])
Expand Down
4 changes: 2 additions & 2 deletions __tests__/Array/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { A } from '../..'

describe('get', () => {
it('should return None', () => {
it('returns None', () => {
expect(A.get([], 0)).toBeNone()
expect(A.get([1, 2, 3], 3)).toBeNone()
})

it('should return Some', () => {
it('returns Some', () => {
expect(A.get([1, 2, 3], 0)).toBeSome(1)
expect(A.get([0, 2, 3], 0)).toBeSome(0)
expect(A.get([true, true, false], 2)).toBeSome(false)
Expand Down
4 changes: 2 additions & 2 deletions __tests__/Array/getBy.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { A } from '../..'

describe('getBy', () => {
it('should return None', () => {
it('returns None', () => {
expect(A.getBy([1, 2, 3], n => n === 0)).toBeNone()
expect(A.getBy([false, false, false], state => state)).toBeNone()
expect(
A.getBy([{ prop: null }, { prop: false }, { prop: undefined }], obj => Boolean(obj.prop)),
).toBeNone()
})

it('should return Some', () => {
it('returns Some', () => {
expect(A.getBy(['a', 'ab', 'bc'], str => str.length === 2)).toBeSome('ab')
expect(A.getBy([1, 2, 3], value => value === 2)).toBeSome(2)
expect(
Expand Down
4 changes: 2 additions & 2 deletions __tests__/Array/head.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { A } from '../..'

describe('head', () => {
it('should return None', () => {
it('returns None', () => {
expect(A.head([])).toBeNone()
})

it('should return Some', () => {
it('returns Some', () => {
expect(A.head([1, 2, 3])).toBeSome(1)
expect(A.head([0, 2, 3])).toBeSome(0)
expect(A.head([false, true, true])).toBeSome(false)
Expand Down
40 changes: 40 additions & 0 deletions __tests__/Array/isEmpty.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expectType } from 'ts-expect'

import { A, pipe } from '../..'

describe('isEmpty', () => {
it('provides correct types', () => {
expectType<boolean>(A.isEmpty([1, 2, 3]))
})

it('returns `true` if the given array is empty', () => {
expect(A.isEmpty([])).toEqual(true)
})

it('returns `false` if the given array is not empty', () => {
expect(A.isEmpty([1, 2, 3])).toEqual(false)
})

it('*', () => {
expect(A.isEmpty(['hello', 'world'])).toEqual(false)
expect(A.isEmpty([])).toEqual(true)
})
})

describe('isEmpty (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe([1, 2, 3], A.isEmpty))
})

it('returns `true` if the given array is empty', () => {
expect(pipe([], A.isEmpty)).toEqual(true)
})

it('returns `false` if the given array is not empty', () => {
expect(pipe([1, 2, 3], A.isEmpty)).toEqual(false)
})

it('*', () => {
expect(pipe([1, 2, 3], A.isEmpty)).toEqual(false)
})
})
40 changes: 40 additions & 0 deletions __tests__/Array/isNotEmpty.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expectType } from 'ts-expect'

import { A, pipe } from '../..'

describe('isNotEmpty', () => {
it('provides correct types', () => {
expectType<boolean>(A.isNotEmpty([1, 2, 3]))
})

it('returns `true` if the given array is not empty', () => {
expect(A.isNotEmpty([1, 2, 3])).toEqual(true)
})

it('returns `false` if the given array is empty', () => {
expect(A.isNotEmpty([])).toEqual(false)
})

it('*', () => {
expect(A.isNotEmpty(['hello', 'world'])).toEqual(true)
expect(A.isNotEmpty([])).toEqual(false)
})
})

describe('isNotEmpty (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe([1, 2, 3], A.isNotEmpty))
})

it('returns `true` if the given array is not empty', () => {
expect(pipe([1, 2, 3], A.isNotEmpty)).toEqual(true)
})

it('returns `false` if the given array is empty', () => {
expect(pipe([], A.isNotEmpty)).toEqual(false)
})

it('*', () => {
expect(pipe([1, 2, 3], A.isNotEmpty)).toEqual(true)
})
})
33 changes: 33 additions & 0 deletions __tests__/Array/length.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expectType } from 'ts-expect'

import { A, pipe } from '../..'

describe('length', () => {
it('provides correct types', () => {
expectType<number>(A.length([1, 2, 3, 4, 5]))
})

it('returns the correct size of the given array', () => {
expect(A.length([1, 2, 3, 4, 5])).toEqual(5)
expect(A.length([])).toEqual(0)
})

it('*', () => {
expect(A.length(['hello', 'world'])).toEqual(2)
})
})

describe('length (pipe)', () => {
it('provides correct types', () => {
expectType<number>(pipe([1, 2, 3], A.length))
})

it('returns the correct size of the given array', () => {
expect(pipe([1, 2, 3], A.length)).toEqual(3)
expect(pipe([], A.length)).toEqual(0)
})

it('*', () => {
expect(pipe([0, 2, 4], A.length)).toEqual(3)
})
})
46 changes: 46 additions & 0 deletions __tests__/Array/make.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expectType } from 'ts-expect'

import { A, pipe } from '../..'

describe('make', () => {
it('provides correct types', () => {
expectType<ReadonlyArray<number>>(A.make(3, 3))
expectType<ReadonlyArray<string>>(A.make(3, 'hello'))
})

it('creates an empty array', () => {
const result = A.make(-1, 'hello')
expect(result).toEqual([])
})

it('creates a new array of size `n`', () => {
const result = A.make(3, 1)
expect(result).toEqual([1, 1, 1])
})

it('*', () => {
expect(A.make(-1, 'hello')).toEqual([])
expect(A.make(3, 1)).toEqual([1, 1, 1])
})
})

describe('make (pipe)', () => {
it('provides correct types', () => {
expectType<ReadonlyArray<string>>(pipe(2, A.make('hello')))
expectType<ReadonlyArray<number>>(pipe(2, A.make(5)))
})

it('creates an empty array', () => {
const result = pipe(-1, A.make('hello'))
expect(result).toEqual([])
})

it('creates a new array of size `n`', () => {
const result = pipe(3, A.make(1))
expect(result).toEqual([1, 1, 1])
})

it('*', () => {
expect(pipe(2, A.make('hello'))).toEqual(['hello', 'hello'])
})
})
18 changes: 18 additions & 0 deletions __tests__/Array/makeEmpty.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expectType } from 'ts-expect'

import { A } from '../..'

describe('makeEmpty', () => {
it('provides correct types', () => {
expectType<ReadonlyArray<number>>(A.makeEmpty<number>())
})

it('creates an empty array', () => {
const result = A.makeEmpty<string>()
expect(result).toEqual([])
})

it('*', () => {
expect(A.makeEmpty<number>()).toEqual([])
})
})
19 changes: 19 additions & 0 deletions __tests__/Array/makeWithIndex.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expectType } from 'ts-expect'

import { A } from '../..'

describe('makeWithIndex', () => {
it('provides correct types', () => {
expectType<ReadonlyArray<string>>(A.makeWithIndex(4, index => `${index}`))
expectType<ReadonlyArray<number>>(A.makeWithIndex(4, index => index * 2))
})

it('returns a new array of size `n`', () => {
const result = A.makeWithIndex(5, index => index * 2)
expect(result).toEqual([0, 2, 4, 6, 8])
})

it('*', () => {
expect(A.makeWithIndex(5, index => index * 2)).toEqual([0, 2, 4, 6, 8])
})
})
37 changes: 37 additions & 0 deletions __tests__/Array/reverse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { expectType } from 'ts-expect'

import { A, pipe } from '../..'

const xs = [1, 2, 3, 4, 5]

describe('reverse', () => {
it('provides correct types', () => {
expectType<ReadonlyArray<number>>(A.reverse(xs))
expectType<ReadonlyArray<string>>(A.reverse(['hello', 'world']))
})

it('returns the provided array in reverse order', () => {
const result = A.reverse(xs)
expect(result).toEqual([5, 4, 3, 2, 1])
})

it('*', () => {
expect(A.reverse([1, 2, 3, 4, 5])).toEqual([5, 4, 3, 2, 1])
})
})

describe('make (pipe)', () => {
it('provides correct types', () => {
expectType<ReadonlyArray<number>>(pipe(xs, A.reverse))
expectType<ReadonlyArray<string>>(pipe(['hello', 'world'], A.reverse))
})

it('returns the provided array in reverse order', () => {
const result = pipe(xs, A.reverse)
expect(result).toEqual([5, 4, 3, 2, 1])
})

it('*', () => {
expect(pipe(['hello', 'world'], A.reverse)).toEqual(['world', 'hello'])
})
})
4 changes: 2 additions & 2 deletions __tests__/Array/splitAt.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { A } from '../..'

describe('splitAt', () => {
it('should return None', () => {
it('returns None', () => {
expect(A.splitAt([], 1)).toBeNone()
expect(A.splitAt([1, 2, 3], -1)).toBeNone()
expect(A.splitAt([1, 2, 3], 4)).toBeNone()
})

it('should return Some', () => {
it('returns Some', () => {
expect(A.splitAt([], 0)).toBeSome([[], []])
expect(A.splitAt([1], 1)).toBeSome([[1], []])
expect(A.splitAt([1, 2], 1)).toBeSome([[1], [2]])
Expand Down
25 changes: 17 additions & 8 deletions __tests__/Array/tail.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { A } from '../..'
import { A, O, pipe } from '../..'

describe('tail', () => {
it('should return None', () => {
expect(A.tail([])).toBeNone()
it('returns None', () => {
expect(A.tail([])).toEqual(O.None)
})

it('should return Some', () => {
expect(A.tail([1, 2, 3])).toBeSome([2, 3])
expect(A.tail([true, true, false])).toBeSome([true, false])
expect(A.tail([{ prop: 1 }, { prop: 2 }])).toBeSome([{ prop: 2 }])
expect(A.tail([[1], [2], [3]])).toBeSome([[2], [3]])
it('returns Some', () => {
expect(A.tail([1, 2, 3])).toEqual(O.Some([2, 3]))
expect(A.tail([true, true, false])).toEqual(O.Some([true, false]))
expect(A.tail([{ prop: 1 }, { prop: 2 }])).toEqual(O.Some([{ prop: 2 }]))
expect(A.tail([[1], [2], [3]])).toEqual(O.Some([[2], [3]]))
})

it('*', () => {
const { Some, None } = O

expect(A.tail([1, 2, 3])).toEqual(Some([2, 3]))
expect(A.tail([1])).toEqual(Some([]))
expect(A.tail([])).toEqual(None)
expect(pipe([1, 2, 3, 4], A.tail)).toEqual(Some([2, 3, 4]))
})
})
4 changes: 2 additions & 2 deletions __tests__/Array/take.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { A } from '../..'

describe('take', () => {
it('should return an empty array', () => {
it('returns an empty array', () => {
expect(A.take([1, 2, 3], -1)).toEqual([])
expect(A.take([], 0)).toEqual([])
expect(A.take([1, 2, 3], 0)).toEqual([])
})

it('should return a new array including the first `n` items', () => {
it('returns a new array including the first `n` items', () => {
expect(A.take([1], 1)).toEqual([1])
expect(A.take([1, 2, 3], 1)).toEqual([1])
expect(A.take([[1], [2]], 1)).toEqual([[1]])
Expand Down
4 changes: 2 additions & 2 deletions __tests__/Option/filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pipe, O } from '../..'

describe('filter', () => {
it('should return None', () => {
it('returns None', () => {
expect(
pipe(
O.fromNullable(null),
Expand All @@ -25,7 +25,7 @@ describe('filter', () => {
).toBeNone()
})

it('should return Some', () => {
it('returns Some', () => {
expect(
pipe(
O.fromNullable([1, 2, 3]),
Expand Down
Loading

0 comments on commit 94ca40a

Please sign in to comment.