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-372-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-374-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/Left.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ function ap() {
return this
}

function getOrElse(defaultValue) {
return defaultValue
}

const prototype = {
'@@type': typeLeft,
ap,
Expand All @@ -51,6 +55,7 @@ const prototype = {
flatMap,
leftMap,
leftFlatMap,
getOrElse,
'fantasy-land/ap': ap,
'fantasy-land/map': map,
inspect() {
Expand Down
5 changes: 5 additions & 0 deletions type/Right.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function ap(right) {
return right.map(this.value)
}

function getOrElse() {
return this.value
}

const prototype = {
'@@type': typeRight,
ap,
Expand All @@ -53,6 +57,7 @@ const prototype = {
flatMap,
leftMap,
leftFlatMap,
getOrElse,
'fantasy-land/ap': ap,
'fantasy-land/map': map,
inspect() {
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 @@ -98,6 +98,13 @@ describe('type/Left', () => {
expect(actual).toBe(expected)
})

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

test('Left(abc).inspect', () => {
expect.assertions(1)
const expected = 'Left ("abc")'
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 @@ -77,6 +77,13 @@ describe('type/Right', () => {
expect(actual).toBe(expected)
})

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

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