Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MojiScript ![project:experimental](https://img.shields.io/badge/project-experimental-orange.svg) [![build status](https://travis-ci.org/joelnet/MojiScript.svg?branch=master)](https://travis-ci.org/joelnet/MojiScript) [![Coverage Status](https://coveralls.io/repos/github/joelnet/MojiScript/badge.svg?branch=master&v=1)](https://coveralls.io/github/joelnet/MojiScript?branch=master) ![project:experimental](https://img.shields.io/badge/tests-374-green.svg) [![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors)
# MojiScript ![project:experimental](https://img.shields.io/badge/project-experimental-orange.svg) [![build status](https://travis-ci.org/joelnet/MojiScript.svg?branch=master)](https://travis-ci.org/joelnet/MojiScript) [![Coverage Status](https://coveralls.io/repos/github/joelnet/MojiScript/badge.svg?branch=master&v=1)](https://coveralls.io/github/joelnet/MojiScript?branch=master) ![project:experimental](https://img.shields.io/badge/tests-380-green.svg) [![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors)

![MojiScript logo](https://raw.githubusercontent.com/joelnet/MojiScript/master/media/MS_logo_64.png)

Expand Down
5 changes: 5 additions & 0 deletions type/Just.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function getOrElse() {
return this.value
}

function getValue(errCallback, dataCallback) {
return dataCallback(this.value)
}

const prototype = {
'@@type': typeJust,
ap,
Expand All @@ -49,6 +53,7 @@ const prototype = {
flatMap,
leftMap,
getOrElse,
getValue,
'fantasy-land/ap': ap,
'fantasy-land/map': map,
toString() { return this.value.toString() },
Expand Down
5 changes: 5 additions & 0 deletions type/Left.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function getOrElse(defaultValue) {
return defaultValue
}

function getValue(errCallback) {
return errCallback(this.value)
}

const prototype = {
'@@type': typeLeft,
ap,
Expand All @@ -56,6 +60,7 @@ const prototype = {
leftMap,
leftFlatMap,
getOrElse,
getValue,
'fantasy-land/ap': ap,
'fantasy-land/map': map,
inspect() {
Expand Down
5 changes: 5 additions & 0 deletions type/Nothing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ function getOrElse(defaultValue) {
return defaultValue
}

function getValue(errCallback) {
return errCallback()
}

const Nothing = Object.freeze(Object.create(
{
'@@type': typeNothing,
Expand All @@ -16,6 +20,7 @@ const Nothing = Object.freeze(Object.create(
leftMap: func => Just(func()),
flatMap: () => Nothing,
getOrElse,
getValue,
'fantasy-land/map': () => Nothing,
toJSON: () => null
},
Expand Down
5 changes: 5 additions & 0 deletions type/Right.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function getOrElse() {
return this.value
}

function getValue(errCallback, dataCallback) {
return dataCallback(this.value)
}

const prototype = {
'@@type': typeRight,
ap,
Expand All @@ -58,6 +62,7 @@ const prototype = {
leftMap,
leftFlatMap,
getOrElse,
getValue,
'fantasy-land/ap': ap,
'fantasy-land/map': map,
inspect() {
Expand Down
7 changes: 7 additions & 0 deletions type/__tests__/Just.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ describe('type/Just', () => {
expect(actual).toBe(expected)
})

test('getValue', () => {
expect.assertions(1)
const expected = 'abc'
const actual = Just('abc').getValue(() => 123, x => x)
expect(actual).toBe(expected)
})

test('fantasy-land/map', () => {
expect.assertions(1)
const expected = 888
Expand Down
7 changes: 7 additions & 0 deletions type/__tests__/Left.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ describe('type/Left', () => {
expect(actual).toBe(expected)
})

test('getValue', () => {
expect.assertions(1)
const expected = 888
const actual = Left(expected).getValue(err => err, () => 123)
expect(actual).toBe(expected)
})

test('Left(abc).inspect', () => {
expect.assertions(1)
const expected = 'Left ("abc")'
Expand Down
6 changes: 6 additions & 0 deletions type/__tests__/Nothing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ describe('type/Nothing', () => {
expect(actual).toBe(expected)
})

test('getValue', () => {
expect.assertions(1)
const expected = 'abc'
const actual = Nothing.getValue(() => expected, () => 123)
expect(actual).toBe(expected)
})

test('fantasy-land/map', () => {
expect.assertions(1)
Expand Down
7 changes: 7 additions & 0 deletions type/__tests__/Right.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ describe('type/Right', () => {
expect(actual).toBe(expected)
})

test('getValue', () => {
expect.assertions(1)
const expected = 888
const actual = Right(expected).getValue(() => 123, data => data)
expect(actual).toBe(expected)
})

test('Right(abc).inspect', () => {
expect.assertions(1)
const expected = 'Right ("abc")'
Expand Down