@grain/stdlib 0.6.5 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +123 -77
- package/bigint.md +30 -30
- package/buffer.gr +20 -53
- package/buffer.md +47 -47
- package/bytes.gr +111 -35
- package/bytes.md +111 -32
- package/char.gr +201 -99
- package/char.md +361 -34
- package/exception.gr +11 -11
- package/exception.md +26 -1
- package/float32.gr +327 -3
- package/float32.md +606 -19
- package/float64.gr +320 -3
- package/float64.md +606 -19
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +102 -14
- package/int16.md +23 -23
- package/int32.gr +25 -4
- package/int32.md +65 -30
- package/int64.gr +26 -1
- package/int64.md +65 -30
- package/int8.md +23 -23
- package/json.gr +366 -51
- package/json.md +418 -2
- package/list.gr +387 -49
- package/list.md +492 -69
- package/map.gr +20 -12
- package/map.md +44 -38
- package/marshal.gr +41 -40
- package/marshal.md +2 -2
- package/number.gr +159 -30
- package/number.md +215 -38
- package/option.md +21 -21
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +103 -12
- package/pervasives.gr +2 -2
- package/pervasives.md +37 -37
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +19 -19
- package/queue.gr +183 -29
- package/queue.md +296 -40
- package/random.md +6 -6
- package/range.gr +4 -4
- package/range.md +6 -6
- package/rational.md +16 -16
- package/regex.gr +52 -51
- package/regex.md +11 -11
- package/result.md +16 -16
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +8 -8
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +1 -1
- package/runtime/dataStructures.md +33 -33
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +1 -1
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +4 -4
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +79 -73
- package/runtime/string.gr +37 -105
- package/runtime/string.md +3 -9
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +13 -13
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +138 -138
- package/set.gr +18 -11
- package/set.md +42 -36
- package/stack.gr +171 -2
- package/stack.md +297 -15
- package/string.gr +352 -557
- package/string.md +77 -34
- package/uint16.gr +81 -0
- package/uint16.md +183 -22
- package/uint32.gr +25 -4
- package/uint32.md +63 -28
- package/uint64.gr +25 -5
- package/uint64.md +63 -28
- package/uint8.gr +81 -0
- package/uint8.md +183 -22
- package/uri.gr +57 -53
- package/uri.md +11 -12
- package/wasi/file.gr +67 -59
- package/wasi/file.md +39 -39
- package/wasi/process.md +5 -5
- package/wasi/random.md +3 -3
- package/wasi/time.md +4 -4
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/json.md
CHANGED
|
@@ -547,7 +547,7 @@ No other changes yet.
|
|
|
547
547
|
</details>
|
|
548
548
|
|
|
549
549
|
```grain
|
|
550
|
-
toString
|
|
550
|
+
toString:
|
|
551
551
|
(?format: FormattingChoices, json: Json) =>
|
|
552
552
|
Result<String, JsonToStringError>
|
|
553
553
|
```
|
|
@@ -616,7 +616,7 @@ No other changes yet.
|
|
|
616
616
|
</details>
|
|
617
617
|
|
|
618
618
|
```grain
|
|
619
|
-
parse
|
|
619
|
+
parse: (str: String) => Result<Json, JsonParseError>
|
|
620
620
|
```
|
|
621
621
|
|
|
622
622
|
Parses JSON string into a `Json` data structure.
|
|
@@ -644,3 +644,419 @@ assert parse("{\"currency\":\"$\",\"price\":119}") == Ok(
|
|
|
644
644
|
)
|
|
645
645
|
```
|
|
646
646
|
|
|
647
|
+
## Json.Lenses
|
|
648
|
+
|
|
649
|
+
Utilities for accessing and updating JSON data.
|
|
650
|
+
|
|
651
|
+
<details disabled>
|
|
652
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
653
|
+
No other changes yet.
|
|
654
|
+
</details>
|
|
655
|
+
|
|
656
|
+
```grain
|
|
657
|
+
let obj = JsonObject([("x", JsonNumber(123))])
|
|
658
|
+
assert get(property("x") ||> number, obj) == Some(123)
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
```grain
|
|
662
|
+
let obj = JsonObject([("x", JsonNumber(123))])
|
|
663
|
+
assert set(property("x") ||> number, 321, obj) ==
|
|
664
|
+
Some(JsonObject([("x", JsonNumber(321))]))
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
### Types
|
|
668
|
+
|
|
669
|
+
Type declarations included in the Json.Lenses module.
|
|
670
|
+
|
|
671
|
+
#### Json.Lenses.**Lens**
|
|
672
|
+
|
|
673
|
+
<details disabled>
|
|
674
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
675
|
+
No other changes yet.
|
|
676
|
+
</details>
|
|
677
|
+
|
|
678
|
+
```grain
|
|
679
|
+
record Lens<a, b> {
|
|
680
|
+
get: (subject: a) => Option<b>,
|
|
681
|
+
set: (newValue: b, subject: a) => Option<a>,
|
|
682
|
+
}
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
A structure which provides functionality for accessing and setting JSON
|
|
686
|
+
data.
|
|
687
|
+
|
|
688
|
+
Fields:
|
|
689
|
+
|
|
690
|
+
|name|type|description|
|
|
691
|
+
|----|----|-----------|
|
|
692
|
+
|`get`|`(subject: a0) => Option<b0>`|A function which reads a value from the subject.|
|
|
693
|
+
|`set`|`(newValue: b0, subject: a0) => Option<a0>`|A function which immutably updates a value in the subject.|
|
|
694
|
+
|
|
695
|
+
### Values
|
|
696
|
+
|
|
697
|
+
Functions and constants included in the Json.Lenses module.
|
|
698
|
+
|
|
699
|
+
#### Json.Lenses.**get**
|
|
700
|
+
|
|
701
|
+
```grain
|
|
702
|
+
get: (lens: Lens<a, b>, subject: a) => Option<b>
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
Reads the value focused on by the given lens from the input data.
|
|
706
|
+
|
|
707
|
+
Parameters:
|
|
708
|
+
|
|
709
|
+
|param|type|description|
|
|
710
|
+
|-----|----|-----------|
|
|
711
|
+
|`lens`|`Lens<a, b>`|The lens to apply to the subject data|
|
|
712
|
+
|`subject`|`a`|The data which will have the lens applied to it|
|
|
713
|
+
|
|
714
|
+
Returns:
|
|
715
|
+
|
|
716
|
+
|type|description|
|
|
717
|
+
|----|-----------|
|
|
718
|
+
|`Option<b>`|`Some(data)` containing the data read by the lens if the lens matches the given data, or `None` if the data cannot be matched to the lens|
|
|
719
|
+
|
|
720
|
+
Examples:
|
|
721
|
+
|
|
722
|
+
```grain
|
|
723
|
+
assert get(number, JsonNumber(123)) == Some(123)
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
```grain
|
|
727
|
+
assert get(string, JsonString("abc")) == Some("abc")
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
```grain
|
|
731
|
+
assert get(number, JsonString("abc")) == None
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
#### Json.Lenses.**set**
|
|
735
|
+
|
|
736
|
+
```grain
|
|
737
|
+
set: (lens: Lens<a, b>, newValue: b, subject: a) => Option<a>
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
Sets the value focused on by the given lens from the input data to the
|
|
741
|
+
desired new value.
|
|
742
|
+
|
|
743
|
+
Parameters:
|
|
744
|
+
|
|
745
|
+
|param|type|description|
|
|
746
|
+
|-----|----|-----------|
|
|
747
|
+
|`lens`|`Lens<a, b>`|The lens to apply to the subject data|
|
|
748
|
+
|`newValue`|`b`|The new value to set at the focus of the lens|
|
|
749
|
+
|`subject`|`a`|The data which will have the lens applied to it|
|
|
750
|
+
|
|
751
|
+
Returns:
|
|
752
|
+
|
|
753
|
+
|type|description|
|
|
754
|
+
|----|-----------|
|
|
755
|
+
|`Option<a>`|`Some(data)` containing the new data after the lens substitution if the lens matches the given data, or `None` if the data cannot be matched to the lens|
|
|
756
|
+
|
|
757
|
+
Examples:
|
|
758
|
+
|
|
759
|
+
```grain
|
|
760
|
+
assert set(number, 123, JsonBoolean(true)) == Some(JsonNumber(123))
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
```grain
|
|
764
|
+
assert set(property("a"), JsonNumber(123), JsonObject([("a", JsonNull)])) == Some(JsonObject([("a", JsonNumber(123))]))
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
```grain
|
|
768
|
+
assert set(property("a"), JsonNumber(123), JsonBoolean(true)) == None
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
#### Json.Lenses.**map**
|
|
772
|
+
|
|
773
|
+
```grain
|
|
774
|
+
map: (lens: Lens<a, b>, fn: (b => b), subject: a) => Option<a>
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
Updates the value focused on by the given lens from the input data by
|
|
778
|
+
applying a function to it and setting the focus to the result of the function
|
|
779
|
+
|
|
780
|
+
Parameters:
|
|
781
|
+
|
|
782
|
+
|param|type|description|
|
|
783
|
+
|-----|----|-----------|
|
|
784
|
+
|`lens`|`Lens<a, b>`|The lens to apply to the subject data|
|
|
785
|
+
|`fn`|`b => b`|The function to apply to the matched data at the lens if matched|
|
|
786
|
+
|`subject`|`a`|The data which will have the lens applied to it|
|
|
787
|
+
|
|
788
|
+
Returns:
|
|
789
|
+
|
|
790
|
+
|type|description|
|
|
791
|
+
|----|-----------|
|
|
792
|
+
|`Option<a>`|`Some(data)` containing the new data after the lens mapping has been applied if the lens matches the given data, or `None` if the data cannot be matched to the lens|
|
|
793
|
+
|
|
794
|
+
Examples:
|
|
795
|
+
|
|
796
|
+
```grain
|
|
797
|
+
assert map(number, x => x * 2, JsonNumber(5)) == Some(JsonNumber(10))
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
```grain
|
|
801
|
+
assert map(property("x"), x => JsonArray([x, x]), JsonObject([("x", JsonNumber(1))])) ==
|
|
802
|
+
Some(JsonObject([("x", JsonArray([JsonNumber(1), JsonNumber(1)]))]))
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
```grain
|
|
806
|
+
assert map(number, x => x * 2, JsonString("abc")) == None
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
#### Json.Lenses.**json**
|
|
810
|
+
|
|
811
|
+
<details disabled>
|
|
812
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
813
|
+
No other changes yet.
|
|
814
|
+
</details>
|
|
815
|
+
|
|
816
|
+
```grain
|
|
817
|
+
json: Lens<Json, Json>
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
A lens whose focus is a JSON value.
|
|
821
|
+
|
|
822
|
+
Examples:
|
|
823
|
+
|
|
824
|
+
```grain
|
|
825
|
+
assert get(json, JsonString("abc")) == Some(JsonString("abc"))
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
#### Json.Lenses.**boolean**
|
|
829
|
+
|
|
830
|
+
<details disabled>
|
|
831
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
832
|
+
No other changes yet.
|
|
833
|
+
</details>
|
|
834
|
+
|
|
835
|
+
```grain
|
|
836
|
+
boolean: Lens<Json, Bool>
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
A lens whose focus is a JSON boolean value.
|
|
840
|
+
|
|
841
|
+
Examples:
|
|
842
|
+
|
|
843
|
+
```grain
|
|
844
|
+
assert get(boolean, JsonBoolean(true)) == Some(true)
|
|
845
|
+
```
|
|
846
|
+
|
|
847
|
+
#### Json.Lenses.**string**
|
|
848
|
+
|
|
849
|
+
<details disabled>
|
|
850
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
851
|
+
No other changes yet.
|
|
852
|
+
</details>
|
|
853
|
+
|
|
854
|
+
```grain
|
|
855
|
+
string: Lens<Json, String>
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
A lens whose focus is a JSON string value.
|
|
859
|
+
|
|
860
|
+
Examples:
|
|
861
|
+
|
|
862
|
+
```grain
|
|
863
|
+
assert get(string, JsonString("abc")) == Some("abc")
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
#### Json.Lenses.**number**
|
|
867
|
+
|
|
868
|
+
<details disabled>
|
|
869
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
870
|
+
No other changes yet.
|
|
871
|
+
</details>
|
|
872
|
+
|
|
873
|
+
```grain
|
|
874
|
+
number: Lens<Json, Number>
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
A lens whose focus is a JSON number value.
|
|
878
|
+
|
|
879
|
+
Examples:
|
|
880
|
+
|
|
881
|
+
```grain
|
|
882
|
+
assert get(number, JsonNumber(123)) == Some(123)
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
#### Json.Lenses.**array**
|
|
886
|
+
|
|
887
|
+
<details disabled>
|
|
888
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
889
|
+
No other changes yet.
|
|
890
|
+
</details>
|
|
891
|
+
|
|
892
|
+
```grain
|
|
893
|
+
array: Lens<Json, List<Json>>
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
A lens whose focus is a JSON array.
|
|
897
|
+
|
|
898
|
+
Examples:
|
|
899
|
+
|
|
900
|
+
```grain
|
|
901
|
+
assert get(array, JsonArray([JsonNumber(123)])) == Some([JsonNumber(123)])
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
#### Json.Lenses.**objectProperties**
|
|
905
|
+
|
|
906
|
+
<details disabled>
|
|
907
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
908
|
+
No other changes yet.
|
|
909
|
+
</details>
|
|
910
|
+
|
|
911
|
+
```grain
|
|
912
|
+
objectProperties: Lens<Json, List<(String, Json)>>
|
|
913
|
+
```
|
|
914
|
+
|
|
915
|
+
A lens whose focus is the property pair list of a JSON object.
|
|
916
|
+
|
|
917
|
+
Examples:
|
|
918
|
+
|
|
919
|
+
```grain
|
|
920
|
+
assert get(objectProperties, JsonObject([("a", JsonNumber(123))])) == Some([("a", JsonNumber(123))])
|
|
921
|
+
```
|
|
922
|
+
|
|
923
|
+
#### Json.Lenses.**property**
|
|
924
|
+
|
|
925
|
+
<details disabled>
|
|
926
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
927
|
+
No other changes yet.
|
|
928
|
+
</details>
|
|
929
|
+
|
|
930
|
+
```grain
|
|
931
|
+
property: (propertyName: String) => Lens<Json, Json>
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
Creates a lens whose focus is a given property of a JSON object.
|
|
935
|
+
|
|
936
|
+
Parameters:
|
|
937
|
+
|
|
938
|
+
|param|type|description|
|
|
939
|
+
|-----|----|-----------|
|
|
940
|
+
|`propertyName`|`String`|The property name of the JSON object to focus on|
|
|
941
|
+
|
|
942
|
+
Returns:
|
|
943
|
+
|
|
944
|
+
|type|description|
|
|
945
|
+
|----|-----------|
|
|
946
|
+
|`Lens<Json, Json>`|A lens whose focus is the given property of a JSON object|
|
|
947
|
+
|
|
948
|
+
Examples:
|
|
949
|
+
|
|
950
|
+
```grain
|
|
951
|
+
assert get(property("x"), JsonObject([("x", JsonNumber(123))])) == Some(JsonNumber(123))
|
|
952
|
+
```
|
|
953
|
+
|
|
954
|
+
```grain
|
|
955
|
+
assert set(property("x"), JsonString("new"), JsonObject([("x", JsonNumber(123))])) ==
|
|
956
|
+
Some(JsonObject([("x", JsonString("new"))]))
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
#### Json.Lenses.**nullable**
|
|
960
|
+
|
|
961
|
+
<details disabled>
|
|
962
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
963
|
+
No other changes yet.
|
|
964
|
+
</details>
|
|
965
|
+
|
|
966
|
+
```grain
|
|
967
|
+
nullable: (lens: Lens<Json, a>) => Lens<Json, Option<a>>
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
Wraps a lens to permit nullable values in addition to the original value
|
|
971
|
+
type of the given lens. During a `get` operation if the lens matches then
|
|
972
|
+
the result will be enclosed in `Some`; if the lens does not match but the
|
|
973
|
+
value focused is null, then the lens will still successfully match and
|
|
974
|
+
`None` will be returned.
|
|
975
|
+
|
|
976
|
+
Examples:
|
|
977
|
+
|
|
978
|
+
```grain
|
|
979
|
+
assert get(nullable(number), JsonNumber(123)) == Some(Some(123))
|
|
980
|
+
```
|
|
981
|
+
|
|
982
|
+
```grain
|
|
983
|
+
assert get(nullable(number), JsonNull) == Some(None)
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
```grain
|
|
987
|
+
assert get(nullable(number), JsonString("abc")) == None
|
|
988
|
+
```
|
|
989
|
+
|
|
990
|
+
```grain
|
|
991
|
+
assert set(nullable(number), Some(123), JsonString("abc")) == Some(JsonNumber(123))
|
|
992
|
+
```
|
|
993
|
+
|
|
994
|
+
#### Json.Lenses.**propertyPath**
|
|
995
|
+
|
|
996
|
+
<details disabled>
|
|
997
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
998
|
+
No other changes yet.
|
|
999
|
+
</details>
|
|
1000
|
+
|
|
1001
|
+
```grain
|
|
1002
|
+
propertyPath: (propertyNames: List<String>) => Lens<Json, Json>
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
Creates a lens whose focus is a given property path within a JSON object tree.
|
|
1006
|
+
|
|
1007
|
+
Parameters:
|
|
1008
|
+
|
|
1009
|
+
|param|type|description|
|
|
1010
|
+
|-----|----|-----------|
|
|
1011
|
+
|`propertyNames`|`List<String>`|The property path of the JSON object to create a focus on|
|
|
1012
|
+
|
|
1013
|
+
Returns:
|
|
1014
|
+
|
|
1015
|
+
|type|description|
|
|
1016
|
+
|----|-----------|
|
|
1017
|
+
|`Lens<Json, Json>`|A lens whose focus is the given property path of a JSON object|
|
|
1018
|
+
|
|
1019
|
+
Examples:
|
|
1020
|
+
|
|
1021
|
+
```grain
|
|
1022
|
+
let nestedObj = JsonObject([("a", JsonObject([("b", JsonNumber(123))]))])
|
|
1023
|
+
assert get(propertyPath(["a", "b"]), nestedObj) == Some(JsonNumber(123))
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
#### Json.Lenses.**(||>)**
|
|
1027
|
+
|
|
1028
|
+
<details disabled>
|
|
1029
|
+
<summary tabindex="-1">Added in <code>0.7.0</code></summary>
|
|
1030
|
+
No other changes yet.
|
|
1031
|
+
</details>
|
|
1032
|
+
|
|
1033
|
+
```grain
|
|
1034
|
+
(||>): (lens1: Lens<a, b>, lens2: Lens<b, c>) => Lens<a, c>
|
|
1035
|
+
```
|
|
1036
|
+
|
|
1037
|
+
Reverse lens composition.
|
|
1038
|
+
|
|
1039
|
+
Parameters:
|
|
1040
|
+
|
|
1041
|
+
|param|type|description|
|
|
1042
|
+
|-----|----|-----------|
|
|
1043
|
+
|`lens1`|`Lens<a, b>`|The lens which will be applied first|
|
|
1044
|
+
|`lens2`|`Lens<b, c>`|The lens which will be applied second|
|
|
1045
|
+
|
|
1046
|
+
Returns:
|
|
1047
|
+
|
|
1048
|
+
|type|description|
|
|
1049
|
+
|----|-----------|
|
|
1050
|
+
|`Lens<a, c>`|A lens which combines the two given lenses, passing through the first and then the second|
|
|
1051
|
+
|
|
1052
|
+
Examples:
|
|
1053
|
+
|
|
1054
|
+
```grain
|
|
1055
|
+
assert get(property("x") ||> number, JsonObject([("x", JsonNumber(123))])) == Some(123)
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
```grain
|
|
1059
|
+
assert set(property("x") ||> string, "new", JsonObject([("x", JsonNumber(123))])) ==
|
|
1060
|
+
Some(JsonObject([("x", JsonString("new"))]))
|
|
1061
|
+
```
|
|
1062
|
+
|