This repository has been archived by the owner on Aug 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Cmd.elm
88 lines (60 loc) · 2.25 KB
/
Cmd.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
module Platform.Cmd exposing
( Cmd
, none
, batch
, map
)
{-|
> **Note:** Elm has **managed effects**, meaning that things like HTTP
> requests or writing to disk are all treated as *data* in Elm. When this
> data is given to the Elm runtime system, it can do some “query optimization”
> before actually performing the effect. Perhaps unexpectedly, this managed
> effects idea is the heart of why Elm is so nice for testing, reuse,
> reproducibility, etc.
>
> Elm has two kinds of managed effects: commands and subscriptions.
# Commands
@docs Cmd, none, batch
# Fancy Stuff
@docs map
-}
import Elm.Kernel.Platform
-- COMMANDS
{-| A command is a way of telling Elm, “Hey, I want you to do this thing!”
So if you want to send an HTTP request, you would need to command Elm to do it.
Or if you wanted to ask for geolocation, you would need to command Elm to go
get it.
Every `Cmd` specifies (1) which effects you need access to and (2) the type of
messages that will come back into your application.
**Note:** Do not worry if this seems confusing at first! As with every Elm user
ever, commands will make more sense as you work through [the Elm Architecture
Tutorial](http://guide.elm-lang.org/architecture/) and see how they
fit into a real application!
-}
type Cmd msg = Cmd
{-| Tell the runtime that there are no commands.
-}
none : Cmd msg
none =
batch []
{-| When you need the runtime system to perform a couple commands, you
can batch them together. Each is handed to the runtime at the same time,
and since each can perform arbitrary operations in the world, there are
no ordering guarantees about the results.
**Note:** `Cmd.none` and `Cmd.batch [ Cmd.none, Cmd.none ]` and `Cmd.batch []`
all do the same thing.
-}
batch : List (Cmd msg) -> Cmd msg
batch =
Elm.Kernel.Platform.batch
-- FANCY STUFF
{-| Transform the messages produced by a command.
Very similar to [`Html.map`](/packages/elm-lang/html/latest/Html#map).
This is very rarely useful in well-structured Elm code, so definitely read the
sections on [reuse][] and [modularity][] in the guide before reaching for this!
[reuse]: https://guide.elm-lang.org/reuse/
[modularity]: https://guide.elm-lang.org/modularity/
-}
map : (a -> msg) -> Cmd a -> Cmd msg
map =
Elm.Kernel.Platform.map