Skip to content

Commit 6a701d1

Browse files
committed
Deprecate constant, compose
1 parent f36ef4d commit 6a701d1

File tree

3 files changed

+7
-40
lines changed

3 files changed

+7
-40
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- The `compose` and `constant` functions in the `function` module have been
6+
deprecated in favour of the `fn` literal syntax.
7+
38
## v0.35.1 - 2024-02-15
49

510
- Fixed a warning on the JavaScript target.

Diff for: src/gleam/function.gleam

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/// Takes two functions and chains them together to form one function that
2-
/// takes the input from the first and returns the output of the second.
3-
///
1+
@deprecated("Use a fn literal instead, it is easier to understand")
42
pub fn compose(fun1: fn(a) -> b, fun2: fn(b) -> c) -> fn(a) -> c {
53
fn(a) { fun2(fun1(a)) }
64
}
@@ -103,9 +101,7 @@ pub fn identity(x: a) -> a {
103101
x
104102
}
105103

106-
/// Takes a single argument and returns a new function that
107-
/// ignores its argument and always returns the input value.
108-
///
104+
@deprecated("Use a fn literal instead, it is easier to understand")
109105
pub fn constant(value: a) -> fn(b) -> a {
110106
fn(_) { value }
111107
}

Diff for: test/gleam/function_test.gleam

-34
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
11
import gleam/function
22
import gleam/int
3-
import gleam/list
43
import gleam/pair
5-
import gleam/result
64
import gleam/should
75
import gleam/string
86

9-
pub fn compose_test() {
10-
let add_two = fn(int: Int) { int + 2 }
11-
let add_three = fn(int: Int) { int + 3 }
12-
13-
let add_five = function.compose(add_two, add_three)
14-
15-
1
16-
|> add_five
17-
|> should.equal(6)
18-
19-
// Takes a list of ints and returns the first as a string (if there is one, or
20-
// else "0" if there is not)
21-
let first_to_string =
22-
list.first
23-
|> function.compose(result.unwrap(_, 0))
24-
|> function.compose(int.to_string)
25-
26-
[1]
27-
|> first_to_string
28-
|> should.equal("1")
29-
30-
[]
31-
|> first_to_string
32-
|> should.equal("0")
33-
}
34-
357
pub fn curry2_test() {
368
let fun = fn(a, b) { a + b }
379
let curried = function.curry2(fun)
@@ -108,12 +80,6 @@ pub fn identity_test() {
10880
|> should.equal(#(1, 2.0))
10981
}
11082

111-
pub fn constant_test() {
112-
#(1, 2)
113-
|> pair.map_first(function.constant(42))
114-
|> should.equal(#(42, 2))
115-
}
116-
11783
pub fn tap_test() {
11884
"Thanks Joe & Louis"
11985
|> function.tap(fn(s: String) {

0 commit comments

Comments
 (0)