Skip to content

Commit

Permalink
Merge pull request #13 from A1c0/fix-index-of
Browse files Browse the repository at this point in the history
fix index of
  • Loading branch information
A1c0 authored Dec 5, 2021
2 parents aea8693 + 6bb3604 commit 9041331
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
. "$(dirname "$0")/_/husky.sh"

yarn sync-doc
yarn test
git add README.md
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ Just (0)

> indexOf ('yellow') (['red', 'green', 'blue'])
Nothing

> indexOf ({name: "white", hex: "#fff"})
. ([{name: "white", hex: "#fff"}, {name: "black", hex: "#000"}])
Just (0)
```

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L79">`splitEach :: PositiveInteger -> Array a -> Array Array a`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L82">`splitEach :: PositiveInteger -> Array a -> Array Array a`</a>

Split an array on sub-array of size N

Expand All @@ -83,7 +87,7 @@ Split an array on sub-array of size N

### Regex

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L104">`extractString :: Regex -> String -> Maybe String`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L107">`extractString :: Regex -> String -> Maybe String`</a>

Get the first group match in a string

Expand All @@ -103,7 +107,7 @@ Nothing
Nothing
```

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L134">`replace :: Regex -> String -> String -> String`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L137">`replace :: Regex -> String -> String -> String`</a>

Replace a substring with a RegExp

Expand All @@ -117,7 +121,7 @@ Replace a substring with a RegExp

### Logic

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L156">`allPass :: Array (a -> Boolean) -> a -> Boolean`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L159">`allPass :: Array (a -> Boolean) -> a -> Boolean`</a>

Return `true` if all predicates return true, else return `false`

Expand All @@ -139,7 +143,7 @@ false
true
```

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L189">`anyPass :: Array (a -> Boolean) -> a -> Boolean`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L192">`anyPass :: Array (a -> Boolean) -> a -> Boolean`</a>

Return `true` if one of predicates return true, else return `false`

Expand All @@ -161,7 +165,7 @@ true
true
```

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L222">`cond :: Array Pair (a -> Boolean) (a -> b) -> a -> Either a b`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L225">`cond :: Array Pair (a -> Boolean) (a -> b) -> a -> Either a b`</a>

Apply transformer predicate return true anc return a Right value
If any predicate return `true`, it will return initial value in Left Value
Expand All @@ -186,7 +190,7 @@ Left ("123!")

Use [implementation created by David Chambers](https://gist.github.com/davidchambers/45aa0187a32fbac6912d4b3b4e8530c5)

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L266">`view :: Lens s a -> s -> a`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L269">`view :: Lens s a -> s -> a`</a>

Allow to get a value by a Lens

Expand All @@ -198,7 +202,7 @@ Allow to get a value by a Lens
dc@davidchambers.me
```

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L278">`over :: Lens s a -> (a -> a) -> s -> s`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L281">`over :: Lens s a -> (a -> a) -> s -> s`</a>

Allow to set a value by a Lens

Expand All @@ -212,7 +216,7 @@ Allow to set a value by a Lens

### Maybe

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L295">`toMaybe :: (a -> Boolean) -> a -> Maybe a`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L298">`toMaybe :: (a -> Boolean) -> a -> Maybe a`</a>

Wrapping value in Maybe depending on predicate

Expand All @@ -229,7 +233,7 @@ Just (1)

### Either

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L320">`toEither :: (a -> Boolean) -> (a -> b) -> a -> Either b a`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L323">`toEither :: (a -> Boolean) -> (a -> b) -> a -> Either b a`</a>

Convert to Either depending on predicate

Expand All @@ -246,7 +250,7 @@ Right (2)

### Fluture

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L345">`flMap :: PositiveNumber -> (a -> Fluture b c) -> Array a -> Fluture b Array c`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L348">`flMap :: PositiveNumber -> (a -> Fluture b c) -> Array a -> Fluture b Array c`</a>

Apply a function that return a Fluture on each item of an array and return a Fluture

Expand All @@ -262,7 +266,7 @@ Apply a function that return a Fluture on each item of an array and return a Flu
[rejection]: "error: 1"
```

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L369">`toFluture :: (a -> Boolean) -> (a -> b) -> a -> Fluture b a`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L372">`toFluture :: (a -> Boolean) -> (a -> b) -> a -> Fluture b a`</a>

Convert to a Fluture depending on predicate

Expand All @@ -277,7 +281,7 @@ Convert to a Fluture depending on predicate
[resolution]: 1
```

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L390">`maybeToFluture :: b -> Maybe a -> Fluture b a`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L393">`maybeToFluture :: b -> Maybe a -> Fluture b a`</a>

Convert a Maybe to a Fluture

Expand All @@ -292,7 +296,7 @@ Convert a Maybe to a Fluture
[rejection]: "not a number"
```

#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L413">`eitherToFluture :: Either a b -> Fluture a b`</a>
#### <a href="https://github.com/A1c0/sanctuary-lourdes/blob/main/index.mjs#L416">`eitherToFluture :: Either a b -> Fluture a b`</a>

Convert an Either to a Fluture

Expand Down
11 changes: 7 additions & 4 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ export const create = ({checkTypes}) => {
//
// > indexOf ('yellow') (['red', 'green', 'blue'])
// Nothing
const _indexOf = elm => array => {
const index = array.indexOf (elm);
return index === -1 ? S.Nothing : S.Just (index);
};
//
// > indexOf ({name: "white", hex: "#fff"})
// . ([{name: "white", hex: "#fff"}, {name: "black", hex: "#000"}])
// Just (0)
const _indexOf = elm => array =>
toMaybe (x => x !== -1) (array.findIndex (x => S.equals (elm) (x)));

const indexOf = def ('indexOf')
({})
([a, $.Array (a), $.Maybe ($.NonNegativeInteger)])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sanctuary-lourdes",
"version": "0.3.0",
"version": "0.3.1",
"main": "index.mjs",
"author": "Alexandre CONTASSOT <alexandrecontassot@hotmail.fr>",
"license": "MIT",
Expand Down

0 comments on commit 9041331

Please sign in to comment.