Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
selfrefactor committed Aug 22, 2024
1 parent ac7eb37 commit deeaf16
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 2 deletions.
10 changes: 9 additions & 1 deletion files/NEXT_VERSION_CHECKLIST.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
throttle should accept 0 arguments, i.e. no need to force unary function

https://github.com/ramda/types/pull/37/files

https://github.com/ramda/types/pull/127/files

---
ABOVE IS DONE
---

https://github.com/ramda/types/pull/127/files
---
ABOVE IS IN PROGRESS
---
Expand Down Expand Up @@ -136,6 +138,12 @@ REFS:

run immutable script
===
https://github.com/ramda/types/pull/101/files

export function last<T>(list: readonly [...any[], T]): T;
export function last<T>(list: ReadonlyNonEmptyArray<T>): T;
export function last<T>(list: readonly T[]): T | undefined;
===
from bookmarks:

https://arethetypeswrong.github.io/?p=ramda%400.29.1
Expand Down
24 changes: 24 additions & 0 deletions files/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export type RambdaTypes = "Object" | "Number" | "Boolean" | "String" | "Null" | "Array" | "RegExp" | "NaN" | "Function" | "Undefined" | "Async" | "Promise" | "Symbol" | "Set" | "Error" | "Map" | "WeakMap" | "Generator" | "GeneratorFunction" | "BigInt" | "ArrayBuffer" | "Date"

export type NonEmptyArray<T> = [T, ...T[]];
export type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];

type LastArrayElement<ValueType extends readonly unknown[]> =
ValueType extends readonly [infer ElementType]
? ElementType
Expand Down Expand Up @@ -1898,6 +1901,7 @@ export function last(list: readonly[]): undefined;
export function last(list: never[]): undefined;
export function last<T extends unknown[]>(array: T): LastArrayElement<T>;
export function last<T extends readonly unknown[]>(array: T): LastArrayElement<T>;
export function last(str: string): string | undefined;

/*
Method: lastIndexOf
Expand Down Expand Up @@ -2680,6 +2684,26 @@ Notes:
// @SINGLE_MARKER
export function not(input: any): boolean;

/*
Method: notEmpty
Explanation:
Example:
```
```
Categories: Logic
Notes:
*/
// @SINGLE_MARKER
export function isNotEmpty<T>(value: T[]): value is NonEmptyArray<T>;
export function isNotEmpty<T>(value: readonly T[]): value is ReadonlyNonEmptyArray<T>;
export function isNotEmpty(value: any): boolean;


/*
Method: nth
Expand Down
19 changes: 19 additions & 0 deletions source/isNotEmpty-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { isNotEmpty } from 'rambda';

describe('R.isNotEmpty', () => {
it('happy', () => {
const readonlyArr: readonly number[] = [];
if (isNotEmpty(readonlyArr)) {
readonlyArr; // $ExpectType ReadonlyNonEmptyArray<number>
}
const tuple: [number, string] = [1, '1'];
if (isNotEmpty(tuple)) {
tuple; // $ExpectType [number, string]
}

const tuple2 = [1, 2, 3] as const;
if (isNotEmpty(tuple2)) {
tuple2; // $ExpectType readonly [1, 2, 3]
}
});
});
5 changes: 5 additions & 0 deletions source/isNotEmpty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { isEmpty } from './isEmpty.js';

export function isNotEmpty(input) {
return !isEmpty(input);
}
16 changes: 16 additions & 0 deletions source/isNotEmpty.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { isNotEmpty } from './isNotEmpty.js'

test('happy', () => {
expect(isNotEmpty(undefined)).toBeTrue()
expect(isNotEmpty('')).toBeFalse()
expect(isNotEmpty(null)).toBeTrue()
expect(isNotEmpty(' ')).toBeTrue()
expect(isNotEmpty(new RegExp(''))).toBeTrue()
expect(isNotEmpty([])).toBeFalse()
expect(isNotEmpty([ [] ])).toBeTrue()
expect(isNotEmpty({})).toBeFalse()
expect(isNotEmpty({ x : 0 })).toBeTrue()
expect(isNotEmpty(0)).toBeTrue()
expect(isNotEmpty(NaN)).toBeTrue()
expect(isNotEmpty([ '' ])).toBeTrue()
})
2 changes: 1 addition & 1 deletion source/lens-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {lens, assoc, lensProp, view, lensIndex, over, lensPath} from 'rambda'
import {lens, assoc, lensProp, view, lensIndex, over, lensPath} from 'ramda'

interface Input {
foo: string,
Expand Down

0 comments on commit deeaf16

Please sign in to comment.