Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,32 @@ Checks if two objects are deeply equal.
```
<!-- prettier-ignore-end -->

#### some

Test if every element passes the given predicate.

##### Type signature

<!-- prettier-ignore-start -->
```typescript
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => boolean
```
<!-- prettier-ignore-end -->

##### Examples

<!-- prettier-ignore-start -->
```javascript
every(x => x >= 0)({ x: 5, y: 3, z: 0 }); // ⇒ true
```

```javascript
every(x => x > 0)({ x: 5, y: 3, z: 0 }); // ⇒ false
```
<!-- prettier-ignore-end -->

#### filter

Filters the given object with the given predicate.
Expand Down Expand Up @@ -2271,6 +2297,32 @@ Checks if the given object is empty.
```
<!-- prettier-ignore-end -->

#### some

Test if any element passes the given predicate.

##### Type signature

<!-- prettier-ignore-start -->
```typescript
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => boolean
```
<!-- prettier-ignore-end -->

##### Examples

<!-- prettier-ignore-start -->
```javascript
some(x => x >= 4)({ x: 5, y: 3, z: 0 }); // ⇒ true
```

```javascript
some(x => x < 0)({ x: 5, y: 3, z: 0 }); // ⇒ false
```
<!-- prettier-ignore-end -->

#### sort

Sorts the given object by a comparator.
Expand Down
52 changes: 52 additions & 0 deletions object/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ Checks if two objects are deeply equal.
```
<!-- prettier-ignore-end -->

# some

Test if every element passes the given predicate.

## Type signature

<!-- prettier-ignore-start -->
```typescript
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => boolean
```
<!-- prettier-ignore-end -->

## Examples

<!-- prettier-ignore-start -->
```javascript
every(x => x >= 0)({ x: 5, y: 3, z: 0 }); // ⇒ true
```

```javascript
every(x => x > 0)({ x: 5, y: 3, z: 0 }); // ⇒ false
```
<!-- prettier-ignore-end -->

# filter

Filters the given object with the given predicate.
Expand Down Expand Up @@ -343,6 +369,32 @@ Checks if the given object is empty.
```
<!-- prettier-ignore-end -->

# some

Test if any element passes the given predicate.

## Type signature

<!-- prettier-ignore-start -->
```typescript
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => boolean
```
<!-- prettier-ignore-end -->

## Examples

<!-- prettier-ignore-start -->
```javascript
some(x => x >= 4)({ x: 5, y: 3, z: 0 }); // ⇒ true
```

```javascript
some(x => x < 0)({ x: 5, y: 3, z: 0 }); // ⇒ false
```
<!-- prettier-ignore-end -->

# sort

Sorts the given object by a comparator.
Expand Down
4 changes: 4 additions & 0 deletions object/every.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import entries from "./entries.js";

export default f => xs =>
entries(xs).every(([key, value]) => f(value, key, xs));
16 changes: 16 additions & 0 deletions object/every.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "some",
"description": "Test if every element passes the given predicate.",
"signature": "(\n f: (value: any, key: string, context: object) => boolean\n) => (xs: object) => boolean",
"examples": [
{
"language": "javascript",
"content": "every(x => x >= 0)({ x: 5, y: 3, z: 0 }); // ⇒ true"
},
{
"language": "javascript",
"content": "every(x => x > 0)({ x: 5, y: 3, z: 0 }); // ⇒ false"
}
],
"questions": ["TODO: List questions that may this function answers."]
}
25 changes: 25 additions & 0 deletions object/every.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# some

Test if every element passes the given predicate.

## Type signature

<!-- prettier-ignore-start -->
```typescript
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => boolean
```
<!-- prettier-ignore-end -->

## Examples

<!-- prettier-ignore-start -->
```javascript
every(x => x >= 0)({ x: 5, y: 3, z: 0 }); // ⇒ true
```

```javascript
every(x => x > 0)({ x: 5, y: 3, z: 0 }); // ⇒ false
```
<!-- prettier-ignore-end -->
27 changes: 27 additions & 0 deletions object/every.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-env jest */
// @ts-ignore ambiguous import
import every from "./every.ts";

describe("every", () => {
it("test if every element passes the given predicate", () => {
const adult = ({ age }: { age: number }) => age >= 18;

expect(
every(adult)({
tom: { age: 25 },
john: { age: 16 },
alice: { age: 18 }
})
).toBe(false);
});

it("test if every element passes the given predicate", () => {
expect(
every((x: number) => x >= 0)({
x: 5,
y: 3,
z: 0
})
).toBe(true);
});
});
5 changes: 5 additions & 0 deletions object/every.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import entries from "./entries";

export default (f: (value: any, key: string, context: object) => boolean) => (
xs: object
): boolean => entries(xs).every(([key, value]) => f(value, key, xs));
6 changes: 6 additions & 0 deletions object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import empty from "./empty.js";
import entries from "./entries.js";
import enumerable from "./enumerable.js";
import equals from "./equals.js";
import every from "./every.js";
import filter from "./filter.js";
import find from "./find.js";
import findEntry from "./findEntry.js";
Expand All @@ -20,6 +21,7 @@ import mapKeys from "./mapKeys.js";
import mapValues from "./mapValues.js";
import merge from "./merge.js";
import none from "./none.js";
import some from "./some.js";
import sort from "./sort.js";

export {
Expand All @@ -29,6 +31,7 @@ export {
entries,
enumerable,
equals,
every,
filter,
find,
findEntry,
Expand All @@ -45,6 +48,7 @@ export {
mapValues,
merge,
none,
some,
sort
};

Expand All @@ -55,6 +59,7 @@ export default {
entries,
enumerable,
equals,
every,
filter,
find,
findEntry,
Expand All @@ -71,5 +76,6 @@ export default {
mapValues,
merge,
none,
some,
sort
};
6 changes: 6 additions & 0 deletions object/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import empty from "./empty";
import entries from "./entries";
import enumerable from "./enumerable";
import equals from "./equals";
import every from "./every";
import filter from "./filter";
import find from "./find";
import findEntry from "./findEntry";
Expand All @@ -20,6 +21,7 @@ import mapKeys from "./mapKeys";
import mapValues from "./mapValues";
import merge from "./merge";
import none from "./none";
import some from "./some";
import sort from "./sort";

export {
Expand All @@ -29,6 +31,7 @@ export {
entries,
enumerable,
equals,
every,
filter,
find,
findEntry,
Expand All @@ -45,6 +48,7 @@ export {
mapValues,
merge,
none,
some,
sort
};

Expand All @@ -55,6 +59,7 @@ export default {
entries,
enumerable,
equals,
every,
filter,
find,
findEntry,
Expand All @@ -71,5 +76,6 @@ export default {
mapValues,
merge,
none,
some,
sort
};
3 changes: 3 additions & 0 deletions object/some.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import entries from "./entries.js";

export default f => xs => entries(xs).some(([key, value]) => f(value, key, xs));
16 changes: 16 additions & 0 deletions object/some.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "some",
"description": "Test if any element passes the given predicate.",
"signature": "(\n f: (value: any, key: string, context: object) => boolean\n) => (xs: object) => boolean",
"examples": [
{
"language": "javascript",
"content": "some(x => x >= 4)({ x: 5, y: 3, z: 0 }); // ⇒ true"
},
{
"language": "javascript",
"content": "some(x => x < 0)({ x: 5, y: 3, z: 0 }); // ⇒ false"
}
],
"questions": ["TODO: List questions that may this function answers."]
}
25 changes: 25 additions & 0 deletions object/some.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# some

Test if any element passes the given predicate.

## Type signature

<!-- prettier-ignore-start -->
```typescript
(
f: (value: any, key: string, context: object) => boolean
) => (xs: object) => boolean
```
<!-- prettier-ignore-end -->

## Examples

<!-- prettier-ignore-start -->
```javascript
some(x => x >= 4)({ x: 5, y: 3, z: 0 }); // ⇒ true
```

```javascript
some(x => x < 0)({ x: 5, y: 3, z: 0 }); // ⇒ false
```
<!-- prettier-ignore-end -->
27 changes: 27 additions & 0 deletions object/some.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-env jest */
// @ts-ignore ambiguous import
import some from "./some.ts";

describe("some", () => {
it("test if any element passes the given predicate", () => {
const adult = ({ age }: { age: number }) => age >= 18;

expect(
some(adult)({
tom: { age: 25 },
john: { age: 16 },
alice: { age: 18 }
})
).toBe(true);
});

it("test if any element passes the given predicate", () => {
expect(
some((x: number) => x < 0)({
x: 5,
y: 3,
z: 0
})
).toBe(false);
});
});
5 changes: 5 additions & 0 deletions object/some.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import entries from "./entries";

export default (f: (value: any, key: string, context: object) => boolean) => (
xs: object
): boolean => entries(xs).some(([key, value]) => f(value, key, xs));