Replies: 1 comment
-
Thanks for the discussion! Some fun ideas 😄 I'm going to move it over to the discussions tab. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just subscribe your episodes. It's great!
In Episode #2 and Episode #3, you introduce
|>
and<>
to pipe and compose for mutator functions.I have some thoughts about it. This is just suggestion and leaving for discussion.
1. Using
|!>
and>!>
to instead of|>
and<>
for mutator functions|!>
is mutator version of|>
>!>
is mutator version of>>>
The operators ending with
!>
(e.g.|!>
and>!>
) indicate that they are mutator operators which introduce mutations (or side effects). When you need to find those mutator operators in the project, this design would be much useful and helpful by searching with regex.The
!
in the operators indicates:Void
;|>
2. Make
|!>
really pipeable/chainable with following|>
In the original implementation, the following code doesn't work:
To make
|!>
pipeable/chainable just like fluent API:Now you can chain up the
|!>
with|>
Note: Yon can't chain up multiple
|!>
with value type mutators, because the return value of the first|!>
is immutable which can't pipe into theinout
mutator again. You need to compose those value type mutators first and pipe:3. Make
|!>
support ref type mutatorsOverload the mutator operators to support ref types:
It makes you possibly chain the ref type mutator functions as following:
It's possible chaining up multiple
|!>
with ref type mutator functions, because the mutator functions don't useinout
.Conclusion
Using mutator operators indicates that it will pipe or compose mutator functions with
Void
return type into the point-free style, including:(inout A) -> Void
(A: AnyObject) -> Void
Using different symbols for mutator operators would be more readable and maintainable. Leave
|>
and<>
for its original meaning (purepipe
and semigroupconcat
).For best practice, you should name the mutator functions with prefix
set
(mutate the state of the data object):Beta Was this translation helpful? Give feedback.
All reactions