1.1.0 • Published 7 years ago

scalts v1.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

Build Status Test Coverage

scalts

The goal of this library is to provide some scala like monades and functional feature.

  • Optional (Some, None)
  • Either (Left, Right)
  • Try (Success, Failure)
  • Future

And have something for-comprehension for each of this features

like scalaz with like a scalaz ApplicativeBuilder.

Installation

npm i scalts --save

Optional

Represents optional values. Instances of Optional are either an instance of Some or the object None.

The goal here is to never use null or undefined (thx to strictNullChecks instruction of TypeScript ).

ìmport { Optional, Some, None } from 'scalts';
const foo: Optional< string >   = Optional.apply( 'Bar' ); // Some( 'Bar' );
const error: Optional< string > = Optional.apply< string >( null ); // None

const mapper: ( s: string ) => {foo: string} = s => { foo: s };

foo.map( mapper ); // Some( { foo: 'Bar' } )
error.map( mapper ); // None
const opt1: Optional< string > = Optional.apply( 'The' );
const opt2: Optional< string > = Optional.apply( 'awser' );
const opt3: Optional< boolean >= Optional.apply( true );
const opt4: Optional< number > = Optional.apply( 42 );
const opt5: Optional< number > = None;


const fn = ( a: string, b: sring, c: boolean, d: number ) => {
   return a + ' ' + b + ' ' + ( c ? 'is' : 'isn\'t' ) + ' ' + d;
}

Some( 'The' ).chain( () => Some( 'answer' ) )
             .chain( () => Some( true ) )
             .chain( () => Some( 42 ) )
             .run( fn ); // Some( 'The answer is 42' );

Some( 'The' ).chain( () => <Optional< string > >None )
             .chain( () => Some( true ) )
             .chain( () => Some( 42 ) )
             .run( fn ); // None

Either

ONGOING

Try

ONGOING

Future

ONGOING

for-comprehension

ONGOING

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.6.0

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

8 years ago

0.4.0-beta2

8 years ago

0.4.0-beta1

8 years ago

0.3.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.1

8 years ago