Skip to content
Jonathan Potter edited this page Jan 26, 2015 · 7 revisions

Maybe(hasValue, [value])

Types

hasValue : Boolean
value : Any (only required if hasValue)
return : Maybe

Typeclass Instances
  • Functor
  • Monad
  • Applicative
Description

Create a Maybe.

A Maybe with hasValue = true and value = 1 will be described in the documentation as Just 1. A Maybe with hasValue = false will be described as Nothing.

Example
var exists = new tlc.Maybe(true, 1);
var doesNotExist = new tlc.Maybe(false);

tlc.map(tlc.op["+"](1), exists); // Just 2
tlc.map(tlc.op["+"](1), doesNotExist); // Nothing

isJust(maybe)

isJust : Maybe a -> Boolean

Types

maybe : Maybe
return : Boolean

Description

Return true if maybe is a Just. Otherwise, return false.

isNothing(maybe)

isNothing : Maybe a -> Boolean

Types

maybe : Maybe
return : Boolean

Description

Return true if maybe is a Nothing. Otherwise, return false.

maybe(defaultValue, f, maybe)

maybe : a -> (a -> b) -> Maybe a -> b

Types

defaultValue : Any
f: Function
maybe: Maybe
return : Any

Description

If maybe is a Just, return the application of f to its value. Otherwise, return defaultValue.

fromMaybe(defaultValue, maybe)

fromMaybe : a -> Maybe a -> a

Types

defaultValue : Any
maybe: Maybe
return : Any

Description

If maybe is a Just, return its value. Otherwise, return defaultValue.

catMaybes(xs)

catMaybes : [Maybe a] -> [a]

Types

xs : Array of Maybes
return : Array

Description

Removes all Nothings from xs and unwraps all Justs. So [Nothing, Just 1, Just 2] will become [1, 2].

mapMaybe(f, xs)

mapMaybe : (a -> Maybe b) -> [a] -> [b]

Types

f : Function returning a Maybe
xs : Array of Maybes
return : Array

Description

Maps f over xs and then catMaybes.

API

  • [Array](API Array)
  • [Function](API Function)
  • [Maybe](API Maybe)
  • [Object](API Object)
  • [Set](API Set)
  • [Typeclass](API Typeclass)

Guides

  • [Operators](Guide Operators)
  • [Typeclasses](Guide Typeclasses)
  • [Replacing OOP](Guide Replacing Object Oriented Programming)

General

Clone this wiki locally