## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Oct 12 21:36
fcallejon edited #60
• Oct 12 21:34
fcallejon edited #60
• Oct 12 21:33
fcallejon opened #60
• Oct 12 21:05
• Aug 10 21:30
• Jun 24 03:00
• Apr 06 08:21
cmeeren commented #59
• Apr 06 08:20
cmeeren commented #59
• Apr 06 08:01
varon commented #59
• Apr 06 06:02
cmeeren commented #59
• Apr 06 06:01
cmeeren commented #59
• Apr 06 02:06
et1975 commented #59
• Apr 05 19:04
cmeeren commented #59
• Apr 05 12:36
varon commented #59
• Mar 30 17:23
cmeeren opened #59
• Jan 27 14:37
LAJW commented #58
• Jan 27 11:06
varon commented #58
• Jan 27 09:22
LAJW commented #58
• Jan 26 20:45
varon commented #58
• Jan 26 20:44
varon commented #58
Alojzy Leszcz
@bratfizyk
however, sometimes 'a is just unit - there are functions in my api that don't require any parameter (e.g. return all the records in an associated db)
and that's the problem
Andrew Cherry
@kolektiv
oh, yes i see what you mean there. hmmm. i'll have a quick look and see if there's a neat way to stick that in (and for FromJson too).
i don't see why not.
Andrew Cherry
@kolektiv
@bratfizyk so, i just pushed out a pre-release of Chiron with a change to support that, if you want to try it. take a dependency on Chiron 6.3.0-rc1 and see whether that works for you :)
Alojzy Leszcz
@bratfizyk
@kolektiv Cool - let me take a look.
Alojzy Leszcz
@bratfizyk
ok - so here's what I found out
My "UseChironProcessor" endpoint now compiles for functions like: unit -> 'a, but the problem is that for "kick" this endpoint, I need to put "null" in GET/POST body.
Ideally I'd like it to work with an empty body, but that would require Chiron to interpret an empty string as a unit value.
Not sure if it's potentially dangerous - what do you think about it ?
Andrew Cherry
@kolektiv
mmmm. have you considered having an optional body type? So Option<Json> or similar? that might make things easier, as any empty body would simply become None - and that maps closer to the semantics of HTTP i think...
(happy to take a look at the source of the ChironProcessor if you like as well, might be able to offer a suggestion!)
it'll be later today though as I have to head for some meetings now, but i'm happy to take a look when i can!
Alojzy Leszcz
@bratfizyk
sure - I'll give a go to your suggestion with the optional body
now that unit values compile, life is a bit simpler
I'll keep you updated
Alojzy Leszcz
@bratfizyk
                  requestBody :=
(let body = (Env.getRequestBody environment) in if String.isNullOrEmpty body then "null" else body)
works for now - hopefully won't bite me too painfully
Andrew Cherry
@kolektiv
that sounds pretty good :) i'd love to see the complete thing and how it works if you can share any of it
Alojzy Leszcz
@bratfizyk
Yeah - that's the problem. It's not my personal project, but a corporate one, so unfortunately I can't share it - sorry for that.
The fix for unit - however - has been working well so far. I'll keep on testing it next week.
Andrew Cherry
@kolektiv
that's no problem - i'm always happy when code is being used, open or not! glad the unit fix is useful, if you don't find issues i might make that final next week
Alojzy Leszcz
@bratfizyk
OK - for sure I'll let you know about my testing experience ;).
Andrew Cherry
@kolektiv
thanks! :)
Alojzy Leszcz
@bratfizyk
Now it's marked as "rc", so no rush - let's make sure it truly deserves becoming an official release ;)
all right - home time; have a good weekend !
Andrew Cherry
@kolektiv
you too!
Alojzy Leszcz
@bratfizyk
Heya - interesting stuff found today:
        let inline serialise (x : 'a) =
(Chiron.Mapping.Json.serialize >> Chiron.Formatting.Json.format) x
and now:
> serialise [| 1; 2 |];;
val it : string = "[1,2]"
but:
> serialise [| "1"; "2" |];;
System.TypeInitializationException: The type initializer for 'Escaping' threw an exception. ---> System.TypeInitializationException: The type initializer for '<StartupCode$Chiron>.$Chiron' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'FParsec, Version=1.0.0.0, Culture=neutral, PublicKeyToken=40ccfc0a09edbb5d' or one of its dependencies. The system cannot find the file specified.
at <StartupCode$Chiron>.$Chiron..cctor()
--- End of inner exception stack trace ---
at Chiron.Escaping..cctor() in C:\projects\chiron\src\Chiron\Chiron.fs:line 0
>    --- End of inner exception stack trace ---
at Chiron.Escaping.escape(String s)
at Chiron.Formatting.formatJson(Int32 level, JsonFormattingOptions options, Json _arg1) in C:\projects\chiron\src\Chiron\Chiron.fs:line 704
at Chiron.Formatting.formatArray@710-1.Invoke(Json _arg1) in C:\projects\chiron\src\Chiron\Chiron.fs:line 710
at Chiron.Formatting.join@667-2.Invoke(StringBuilder b) in C:\projects\chiron\src\Chiron\Chiron.fs:line 670
at Chiron.Formatting.formatArray@708-4.Invoke(StringBuilder x) in C:\projects\chiron\src\Chiron\Chiron.fs:line 708
at Chiron.Formatting.formatArray@708-5.Invoke(StringBuilder x) in C:\projects\chiron\src\Chiron\Chiron.fs:line 708
at Chiron.Formatting.Json.format(Json json) in C:\projects\chiron\src\Chiron\Chiron.fs:line 743
at <StartupCode$FSI_0005>.$FSI_0005.main@()
Stopped due to error
So serialising an array of ints works fine, but doesn't work with an array of strings.
Can you try it as well ?
Andrew Cherry
@kolektiv
i'll have a look when i get a chance a little later! i'd start by seeing if i can work out why there's a file not found error for fparsec - that might well be related, but it's odd that it would be intermittent.
Alojzy Leszcz
@bratfizyk
ok - feel free to ignore this
I've just checked that after some paket-magic I had done, my project lost a reference to FParsec
After fixing that all fine
sorry for the false alarm
Andrew Cherry
@kolektiv
no problem :)
Alojzy Leszcz
@bratfizyk
Heya - about the unit feature testing: so far so good
Andrew Cherry
@kolektiv
:) sounds good!
Stefan Reichel
@stefan-akelius
This message was deleted
btrepp
@btrepp

With lenses and prisms, is there a guide in which it is appropriate to use either?. are prisms mainly for nested datastructures?. In freya the IfMatch_ header is returned as an IfMatch option Lens, rather than an IfMatch prism.

Say i wanted to deal with some nested values, it would make sense to use an epimorphism eg ifmatchweaktag_: Epimorphism<IfMatch,EntityTag.Weak>
But then with IfMatch itself being a Lens<IfMatch option> this doesn't compose.

I have written a composing epimorphism

      let private toPrism_ : Epimorphism<'T option, 'T> = (fun x -> x),
(fun v -> Some v)

but I'm not sure if this is idiomatic. I ask because I have my own lens in freya for the ClaimsPrincipal Lens<State,ClaimsPrincipal option>, which I can see the advantage for (eg my middeware could remove the claims principal if it wants to), but then most uses I can think of would want Prism<State,ClaimsPrincipal>.

varon
@varon
@btrepp Andrew will have a better answer, but from my experience, there's no harm in providing both.
Especially if you're providing a library, it can be a lot easier to work with if the lenses/prisms already exist.
Jon Schoning
@jonschoning

https://xyncro.tech/aether/guides/morphisms.html

type Epimorphism<'a,'b> = ('a -> 'b option) * ('b -> 'a)
My understanding of epi is that it is morally surjective; wouldn't a function from 'a to 'b always have to succeed/produce a value then, because surjection means that the entire codomain receives a value?

Jon Schoning
@jonschoning
i think it makes sense if we're considering the function from going from the preimage of 'a instead of the domain of 'a, then in that case there could be values in the domain of 'a that the function doesn't act on
Jon Schoning
@jonschoning
epimorphism would look more like ('a -> 'b) * ('b -> NonEmptySeq<'a>)