Closed ilyash-b closed 7 months ago
Hi @antonio-pedro99!
In general, ensure(original, pattern)
returns a value which would match the pattern. The operation to make the original conform to the pattern should be minimal and obvious.
my_arr = [1,2,3]
my_arr =~ Has(1) # true
my_arr =~ Has(4) # false
ensure(my_arr, Has(4)) # [1,2,3,4]
I did not understand this
ensure(my_arr, Has(4))
Returning 1, 2, 3 + the element that is not present.
Not sure I understand your comment. I'll try to explain slightly different and see if it works.
ensure(x, pattern)
should return a value that would match the pattern
. In other words, ensure(x, pattern) =~ pattern
should succeed.
x =~ pattern
when ensure()
is called, it just needs to return x
ensure()
should minimally transform (a copy of) x
so that returned value matches the pattern
In the example of ensure(my_arr, Has(4))
, where 4
is not in my_arr
that minimal transformation would be to return a new value with all the elements of my_arr
with the item 4
appended.
In dev
Hi @ilyash-b, could you provide more info on this?