Module: Jade::Stdlib::Maybe
Instance Method Summary
collapse
Methods included from Compiled
entry, generate_entry, resolve_imports, symbols
Instance Method Details
#code ⇒ Object
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
|
# File 'lib/jade/stdlib/maybe.rb', line 25
def code
<<~JADE
module Maybe exposing (Maybe(..), and_then, map, with_default)
type Maybe(a)
= Just(a)
| Nothing
def with_default(maybe: Maybe(a), default: a) -> a
case maybe
in Just(something) then something
in Nothing then default
end
end
def map(maybe: Maybe(a), fn: a -> b) -> Maybe(b)
case maybe
in Just(something)
something
|> fn
|> Just
in Nothing then Nothing
end
end
def and_then(maybe: Maybe(a), fn: a -> Maybe(b)) -> Maybe(b)
case maybe
in Just(something) then something |> fn
in Nothing then Nothing
end
end
implements Mappable(Maybe(a)) with
map: map
end
implements Chainable(Maybe(a)) with
and_then: and_then
end
JADE
end
|
#default_imports ⇒ Object
#imports ⇒ Object
13
14
15
|
# File 'lib/jade/stdlib/maybe.rb', line 13
def imports
[Basics]
end
|
#uri ⇒ Object
9
10
11
|
# File 'lib/jade/stdlib/maybe.rb', line 9
def uri
'maybe.jd'
end
|