Skip to content

Commit 054bfd8

Browse files
committed
Lesson 26 annotate
1 parent 6e81353 commit 054bfd8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

examples/26-isomorphism.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
const { Box, Either, Right, Left, fromNullable } = require('../examples/lib')
2-
32
const { List } = require('immutable-ext')
4-
53
const Task = require('data.task')
64

7-
8-
5+
// general isomorphism signature
96
const Iso = (to, from) => ({
107
to,
118
from
129
})
1310

11+
// isomorphisms String <-> Array
1412
const chars = Iso(
1513
s => s.split(''),
1614
c => c.join('')
@@ -30,7 +28,10 @@ const truncate = str =>
3028
.concat('...')
3129
)
3230

33-
console.log( truncate('hello world') )
31+
console.log(
32+
'hello world truncated is:',
33+
truncate('hello world')
34+
)
3435

3536

3637
// [a] ~ Either null a
@@ -39,7 +40,7 @@ const singleton = Iso(
3940

4041
// Either into Array
4142
// 'fold' is used to extract value
42-
e => e.fold( () => [], x => [x] ),
43+
e => e.fold( _ => [], x => [x] ),
4344

4445
// Array into Either
4546
([x]) => x ? Right(x) : Left()
@@ -48,8 +49,10 @@ const singleton = Iso(
4849
// filtering Either type objects
4950
// transform to Array, filter, than back to Either
5051
const filterEither = (e, pred) =>
51-
singleton.from(
52-
singleton.to(e)
52+
singleton
53+
.from(
54+
singleton
55+
.to(e)
5356
.filter(pred)
5457
)
5558

0 commit comments

Comments
 (0)