From 3599e3c29c16c2cfd12c76a5dcbe6d55e9f396d3 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Mon, 6 Dec 2021 22:23:03 +0000 Subject: Add function.constant This change adds a new helper to the function module. --- src/gleam/function.gleam | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/gleam/function.gleam b/src/gleam/function.gleam index a6d2063..5aebb76 100644 --- a/src/gleam/function.gleam +++ b/src/gleam/function.gleam @@ -51,3 +51,10 @@ pub fn flip(fun: fn(a, b) -> c) -> fn(b, a) -> c { pub fn identity(x: a) -> a { x } + +/// A 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 } +} -- cgit v1.2.3