File tree 3 files changed +7
-40
lines changed
3 files changed +7
-40
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
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
+
3
8
## v0.35.1 - 2024-02-15
4
9
5
10
- Fixed a warning on the JavaScript target.
Original file line number Diff line number Diff line change 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" )
4
2
pub fn compose ( fun1 : fn ( a) -> b, fun2 : fn ( b) -> c) -> fn ( a) -> c {
5
3
fn ( a ) { fun2 ( fun1 ( a ) ) }
6
4
}
@@ -103,9 +101,7 @@ pub fn identity(x: a) -> a {
103
101
x
104
102
}
105
103
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" )
109
105
pub fn constant ( value : a) -> fn ( b) -> a {
110
106
fn ( _ ) { value }
111
107
}
Original file line number Diff line number Diff line change 1
1
import gleam/function
2
2
import gleam/int
3
- import gleam/list
4
3
import gleam/pair
5
- import gleam/result
6
4
import gleam/should
7
5
import gleam/string
8
6
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
-
35
7
pub fn curry2_test ( ) {
36
8
let fun = fn ( a , b ) { a + b }
37
9
let curried = function . curry2 ( fun )
@@ -108,12 +80,6 @@ pub fn identity_test() {
108
80
|> should . equal ( # ( 1 , 2.0 ) )
109
81
}
110
82
111
- pub fn constant_test ( ) {
112
- # ( 1 , 2 )
113
- |> pair . map_first ( function . constant ( 42 ) )
114
- |> should . equal ( # ( 42 , 2 ) )
115
- }
116
-
117
83
pub fn tap_test ( ) {
118
84
"Thanks Joe & Louis"
119
85
|> function . tap ( fn ( s : String ) {
You can’t perform that action at this time.
0 commit comments