-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.6.3 | ||
|
||
* Add `coerce.array` | ||
|
||
## 0.6.2 - 2022-09-29 | ||
|
||
* Add `key_hash` option to `core.mapping`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# coerce.array | ||
|
||
Coerces the input value to an array | ||
|
||
``` | ||
coerce.array: Any -> Array | ||
``` | ||
|
||
This lens convert its input to an Array. | ||
|
||
Mimicing ruby, null is coerced to an empty array. | ||
An array is kept unchanged. | ||
Any other value is converted to a singleton array. | ||
|
||
## Example | ||
|
||
Applying the following lens: | ||
|
||
```yaml | ||
--- | ||
array.map: | ||
on_error: 'null' | ||
lenses: | ||
- coerce.array | ||
``` | ||
to the following input: | ||
```yaml | ||
--- | ||
- ~ | ||
- 'foo' | ||
- ['foo', 'bar'] | ||
``` | ||
will return: | ||
```yaml | ||
--- | ||
- [] | ||
- ['foo'] | ||
- ['foo', 'bar'] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Monolens | ||
module Coerce | ||
class Array | ||
include Lens | ||
|
||
signature(Type::Any, Type::Array) | ||
|
||
def call(arg, world = {}) | ||
Array(arg) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'spec_helper' | ||
|
||
describe Monolens, 'coerce.array' do | ||
subject do | ||
Monolens.lens('coerce.array') | ||
end | ||
|
||
it 'works' do | ||
expect(subject.call(12)).to eql([12]) | ||
expect(subject.call(nil)).to eql([]) | ||
expect(subject.call([12, 13])).to eql([12, 13]) | ||
end | ||
end |