diff options
author | inoas <mail@inoas.com> | 2022-04-04 22:03:19 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-04-06 10:58:14 +0100 |
commit | cbcbe39212027c9aea913df6d00585421156493c (patch) | |
tree | b03f44e91a4a384827abeafe41cd456caf491afc | |
parent | 176a1ab95f69613733fef231a2c6de75817588d2 (diff) | |
download | gleam_stdlib-cbcbe39212027c9aea913df6d00585421156493c.tar.gz gleam_stdlib-cbcbe39212027c9aea913df6d00585421156493c.zip |
Add tap/1
Shamelessy stolen and adopted from @hayleigh-dot-dev and https://hexdocs.pm/elixir/main/Kernel.html#tap/2
-rw-r--r-- | src/gleam/function.gleam | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/gleam/function.gleam b/src/gleam/function.gleam index 5aebb76..007eded 100644 --- a/src/gleam/function.gleam +++ b/src/gleam/function.gleam @@ -52,9 +52,18 @@ pub fn identity(x: a) -> a { x } -/// A function that takes a single argument and returns a new function that +/// Takes a single argument and returns a new function that /// ignores its argument and always returns the input value. /// pub fn constant(value: a) -> fn(b) -> a { fn(_) { value } } + +/// Takes a function with a single argument +/// calls that function with that argument +/// and returns that argument instead of the function return value. +/// Useful for running synchronous side effects in a pipeline. +pub fn tap (arg, effect: fn (a) -> b) -> a { + effect(arg) + arg +} |