Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
brekk committed Mar 28, 2024
1 parent 1b0a4bb commit 53590f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions prelude/__internal__/Function.mad
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export when = (predicate, truthy, value) => ifElse(predicate, truthy, always(val
* otherwise return the initial value.
* @since 0.23.1
* @example
* unless(equals(5), (x) => x * 10, 5) //
* unless(equals(5), (x) => x * 10, 5) // 5
* unless(equals(5), (x) => x * 10, 4) // 40
*/
unless :: (a -> Boolean) -> (a -> a) -> a -> a
export unless = (predicate, falsy, value) => ifElse(predicate, always(value), falsy, value)
Expand Down Expand Up @@ -142,7 +143,6 @@ export noop = (_) => ({})
flip :: (a -> b -> c) -> b -> a -> c
export flip = (f) => ((b, a) => f(a, b))


/**
* Functional "or", given two predicates and a value, return true if either predicate is true.
*
Expand Down
2 changes: 1 addition & 1 deletion prelude/__internal__/List.mad
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ export all = (predicate, list) => where(list) {
}

/**
* Cut a given array at the specificed index and return a tuple of #[beforeIndex, afterIndex] slices
* Cut a given array at the specific index and return a tuple of #[beforeIndex, afterIndex] slices
* @since 0.23.1
* @example
* cut(5, range(1, 11)) // #[ [1,2,3,4,5], [6,7,8,9,10]]
Expand Down
24 changes: 24 additions & 0 deletions prelude/__internal__/Tuple.mad
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
/**
* Get the first value of a binary tuple
* @since 0.23.1
* @example
* fst(#["a", "b"]) // "a"
*/
fst :: #[a, b] -> a
export fst = (tuple) => where(tuple) {
#[a, _] =>
a
}

/**
* Get the second value of a binary tuple
* @since 0.23.1
* @example
* snd(#["a", "b"]) // "b"
*/
snd :: #[a, b] -> b
export snd = (tuple) => where(tuple) {
#[_, b] =>
b
}

/**
* Transform the first value of a binary tuple
* @since 0.23.1
* @example
* mapFst(Math.times(2), #[3, 4]) // #[6, 4]
*/
mapFst :: (a -> b) -> #[a, c] -> #[b, c]
export mapFst = (fn, tuple) => where(tuple) {
#[a, b] =>
#[fn(a), b]
}

/**
* Transform the second value of a binary tuple
* @since 0.23.1
* @example
* mapFst(Math.times(2), #[3, 4]) // #[3, 8]
*/
mapSnd :: (b -> c) -> #[a, b] -> #[a, c]
export mapSnd = (fn, tuple) => where(tuple) {
#[a, b] =>
Expand Down

0 comments on commit 53590f9

Please sign in to comment.