@@ -441,6 +441,24 @@ last([1, "test", 3]); // => 3
441441last (" hello world!" ); // => "!"
442442```
443443
444+ ### lens
445+
446+ ** lens** lens returns a special lens object that can be used as a function setter/getter.
447+
448+ ``` typescript
449+ import lens from " https://deno.land/x/denofun/lens.ts" ;
450+
451+ const car = Object .freeze ({
452+ make: " Toyota" ,
453+ model: " GT86" ,
454+ });
455+
456+ const getCarModel = (data : { make: string , model: string }) => data .model ;
457+ const setCarModel = (data : { make: string , model: string }, value : string ) => ({ ... data , model: value });
458+
459+ const carModelLens = lens (getCarModel , setCarModel ); // => Lens<Car, string>
460+ ```
461+
444462### map
445463
446464** map** applies a function to each element of the array, returns the array of results.
@@ -602,7 +620,29 @@ reverse([1, 2, 3, 4, 5]); // => [5, 4, 3, 2, 1]
602620reverse (" hello world!" ); // => ["!dlrow olleh"]
603621```
604622
605- ** slice** return a given slice of an array or string (wrapper over Array.prototype.slice)
623+ ### set
624+
625+ ** set** uses a provided lens, copies the provided object with a changed value.
626+
627+ ``` typescript
628+ import lens from " https://deno.land/x/denofun/lens.ts" ;
629+ import set from " https://deno.land/x/denofun/set.ts" ;
630+
631+ const car = Object .freeze ({
632+ make: " Toyota" ,
633+ model: " GT86" ,
634+ });
635+
636+ const getCarModel = (data : { make: string , model: string }) => data .model ;
637+ const setCarModel = (data : { make: string , model: string }, value : string ) => ({ ... data , model: value });
638+
639+ const carModelLens = lens (getCarModel , setCarModel );
640+ set (carModelLens , car , " Mirai" ); // => { make: "Toyota", model: "Mirai" }
641+ ```
642+
643+ ### slice
644+
645+ ** slice** return a given slice of an array or string (wrapper over Array.prototype.slice).
606646
607647``` typescript
608648import slice from " https://deno.land/x/denofun/slice.ts" ;
@@ -676,6 +716,26 @@ const car = { make: "Alfa Romeo", model: "Giulia" };
676716values (car ); // => ["make", "model"]
677717```
678718
719+ ### view
720+
721+ ** view** uses a lens to get value from an object.
722+
723+ ``` typescript
724+ import lens from " https://deno.land/x/denofun/lens.ts" ;
725+ import view from " https://deno.land/x/denofun/view.ts" ;
726+
727+ const car = Object .freeze ({
728+ make: " Toyota" ,
729+ model: " GT86" ,
730+ });
731+
732+ const getCarModel = (data : { make: string , model: string }) => data .model ;
733+ const setCarModel = (data : { make: string , model: string }, value : string ) => ({ ... data , model: value });
734+
735+ const carModelLens = lens (getCarModel , setCarModel );
736+ view (carModelLens , car ); // => "GT86"
737+ ```
738+
679739## For Developers
680740
681741If you want to contribute to Denofun:
0 commit comments