Skip to content

Commit cdacbd5

Browse files
committed
Add static syntax examples
1 parent bb56700 commit cdacbd5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

examples/18-applicative.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const res =
88
// apply our wrapped function to the Box'ed value 2
99
.ap(Box(2))
1010

11-
// This uses switched order comparing
11+
// This uses switched order comparing
1212
// to the Fantasy Land applicative spec
1313
// ap :: f a ~> f (a -> b) -> f b
1414

@@ -34,3 +34,14 @@ const add = x => y => x + y
3434

3535
console.log(liftA2(add, Box(2), Box(4)))
3636
// -> Box(6)
37+
38+
console.log(liftA2(x => y => x - y, Box(2), Box(4)))
39+
// -> Box(-2)
40+
41+
42+
// static syntax
43+
// ap(Fg)(Fx, Fy)
44+
const ap = Fg => (Fx, Fy) => Fg.ap(Fx).ap(Fy)
45+
46+
// liftA2cur(g)(Fx, Fy)
47+
const liftA2cur = g => (Fx, Fy) => liftA2(g, Fx, Fy)

0 commit comments

Comments
 (0)