https://github.com/ajermakovics/optional
Optional (Maybe) type in Wren programming language https://wren.io
https://github.com/ajermakovics/optional
maybe optional wren
Last synced: about 1 month ago
JSON representation
Optional (Maybe) type in Wren programming language https://wren.io
- Host: GitHub
- URL: https://github.com/ajermakovics/optional
- Owner: ajermakovics
- License: mit
- Created: 2020-06-28T13:41:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-28T16:57:27.000Z (over 5 years ago)
- Last Synced: 2025-01-30T07:11:15.287Z (about 1 year ago)
- Topics: maybe, optional, wren
- Homepage:
- Size: 2.93 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Optional
Optional type in Wren programming language https://wren.io
An optional can contain a single value or be empty.
## Examples
```
var maybe = Optional.of("abc") // Optional("abc")
maybe.isPresent() // true
maybe.each { |value| System.print(value) } // prints "abc"
var maybe2 = maybe.map { |str| str + "123" } // Optional("abc123")
var none = Optional.empty() // Optional()
System.print(none.getOr("defaultValue")) // "defaultValue"
// pick one of three optionals - first which is not empty
var maybe3 = maybeThis | orThis | maybe2 // Optional("abc123")
var res = Optional.of(request.param).filter { |v| v.count > 0 }.map { |v| v.trim() } // request param without spaces
var combined = Optional.of(1) + Optional.of(2) // Optional(3)
var reqParam = combined.flatMap {|value| Optional.of(value + 100) } // Optional(103)
System.print(reqParam.contains(103)) // true
```
## Usage
```
import "./optional/optional" for Optional
```