1
1
const { Box, Either, Right, Left, fromNullable } = require ( '../examples/lib' )
2
-
3
2
const { List } = require ( 'immutable-ext' )
4
-
5
3
const Task = require ( 'data.task' )
6
4
7
-
8
-
5
+ // general isomorphism signature
9
6
const Iso = ( to , from ) => ( {
10
7
to,
11
8
from
12
9
} )
13
10
11
+ // isomorphisms String <-> Array
14
12
const chars = Iso (
15
13
s => s . split ( '' ) ,
16
14
c => c . join ( '' )
@@ -30,7 +28,10 @@ const truncate = str =>
30
28
. concat ( '...' )
31
29
)
32
30
33
- console . log ( truncate ( 'hello world' ) )
31
+ console . log (
32
+ 'hello world truncated is:' ,
33
+ truncate ( 'hello world' )
34
+ )
34
35
35
36
36
37
// [a] ~ Either null a
@@ -39,7 +40,7 @@ const singleton = Iso(
39
40
40
41
// Either into Array
41
42
// 'fold' is used to extract value
42
- e => e . fold ( ( ) => [ ] , x => [ x ] ) ,
43
+ e => e . fold ( _ => [ ] , x => [ x ] ) ,
43
44
44
45
// Array into Either
45
46
( [ x ] ) => x ? Right ( x ) : Left ( )
@@ -48,8 +49,10 @@ const singleton = Iso(
48
49
// filtering Either type objects
49
50
// transform to Array, filter, than back to Either
50
51
const filterEither = ( e , pred ) =>
51
- singleton . from (
52
- singleton . to ( e )
52
+ singleton
53
+ . from (
54
+ singleton
55
+ . to ( e )
53
56
. filter ( pred )
54
57
)
55
58
0 commit comments