-
Notifications
You must be signed in to change notification settings - Fork 63
/
Basics.elm
98 lines (61 loc) · 2.3 KB
/
Basics.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module Morphir.SDK.Basics exposing
( append
, identity, always
, composeLeft, composeRight
)
{-| Mirror of the `Basics` module in `elm/core` with some modifications for Morphir:
- Operators are replaced with named functions.
- The Morphir Elm frontend maps operators to these named functions.
- `Never` type and `never` value are excluded since business logic should never use these.
- `<|` and `|>` operators are excluded since they are purely syntactic.
- The Morphir Elm frontend replaces `<|` with simple function application and `|>` with function application wit
reversed argument order.
- Some functions excluded do to being too graphics specific:
- degrees, radians, turns, toPolar, fromPolar
# Append Strings and Lists
@docs append
# Function Helpers
@docs identity, always, apL, apR, composeL, composeR
-}
-- APPEND
{-| Put two appendable things together. This includes strings and lists.
"hello" ++ "world" == "helloworld"
[ 1, 1, 2 ] ++ [ 3, 5, 8 ] == [ 1, 1, 2, 3, 5, 8 ]
-}
append : appendable -> appendable -> appendable
append =
(++)
-- FUNCTION HELPERS
{-| Function composition, passing results along in the suggested direction. For
example, the following code checks if the square root of a number is odd:
not << isEven << sqrt
You can think of this operator as equivalent to the following:
(g << f) == (\x -> g (f x))
So our example expands out to something like this:
\n -> not (isEven (sqrt n))
-}
composeLeft : (b -> c) -> (a -> b) -> (a -> c)
composeLeft g f x =
g (f x)
{-| Function composition, passing results along in the suggested direction. For
example, the following code checks if the square root of a number is odd:
sqrt >> isEven >> not
-}
composeRight : (a -> b) -> (b -> c) -> (a -> c)
composeRight f g x =
g (f x)
{-| Given a value, returns exactly the same value. This is called
[the identity function](https://en.wikipedia.org/wiki/Identity_function).
-}
identity : a -> a
identity x =
Basics.identity x
{-| Create a function that _always_ returns the same value. Useful with
functions like `map`:
List.map (always 0) [1,2,3,4,5] == [0,0,0,0,0]
-- List.map (\_ -> 0) [1,2,3,4,5] == [0,0,0,0,0]
-- always = (\x _ -> x)
-}
always : a -> b -> a
always a b =
Basics.always a b