8000 GitHub - stla/Either: The 'Either' type in R.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

stla/Either

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Either: the ‘Either’ type in R

R-CMD-check

library(Either)
## ------------------------------------------------
## Method `Either$new`
## ------------------------------------------------

Either$new("left", 123)
## Left
## [1] 123


## ------------------------------------------------
## Method `Either$isLeft`
## ------------------------------------------------

Either$new("right", 999)$isLeft()
## [1] FALSE

## ------------------------------------------------
## Method `Either$isRight`
## ------------------------------------------------

Either$new("right", 999)$isRight()
## [1] TRUE

## ------------------------------------------------
## Method `Either$getLeft`
## ------------------------------------------------

Either$new("right", 999)$getLeft("abc")
## [1] "abc"

## ------------------------------------------------
## Method `Either$getRight`
## ------------------------------------------------

Either$new("right", 999)$getRight("abc")
## [1] 999

## ------------------------------------------------
## Method `Either$toMaybe`
## ------------------------------------------------

Either$new("right", 999)$toMaybe()
## Just
## [1] 999
Either$new("left", 999)$toMaybe()
## Nothing

## ------------------------------------------------
## Method `Either$mapLeft`
## ------------------------------------------------

Either$new("left", 999)$mapLeft(is.numeric)
## Left
## [1] TRUE
Either$new("right", 999)$mapLeft(is.numeric)
## Right
## [1] 999

## ------------------------------------------------
## Method `Either$mapRight`
## ------------------------------------------------

Either$new("left", 999)$mapRight(is.numeric)
## Left
## [1] 999
Either$new("right", 999)$mapRight(is.numeric)
## Right
## [1] TRUE

## ------------------------------------------------
## Method `Either$either`
## ------------------------------------------------

Either$new("left", 999)$either(is.numeric, is.character)
## Left
## [1] TRUE
Either$new("right", 999)$either(is.numeric, is.character)
## Right
## [1] FALSE
## ------------------------------------------------
## Functions `Left` and `Right` (shortcuts)
## ------------------------------------------------
Left("abc")
## Left
## [1] "abc"
Right("abc")
## Right
## [1] "abc"
## ------------------------------------------------
## Function `eitherFromMaybe` 
## ------------------------------------------------
library(maybe)
eitherFromMaybe("abc", nothing())
## Left
## [1] "abc"
eitherFromMaybe("abc", just(123))
## Right
## [1] 123

About

The 'Either' type in R.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published
2FE3

Packages

No packages published

Languages

0