Après avoir montré un Validator en FP dans une première vidéo, je passe à la seconde qui montre la refacto d'un code legacy vers du FP en simulant un Pattern Guards :
youtu.be/DFQHYY9_mfs
J'espère que ca vous plaira :)
@java#FP#refacto#legacy#PatternGuards#lambda
It is || just written with funny alignment. Unfortunately, combining this trick with PatternGuards is not enough to have Or-Patterns 😞 There was a nice proposal by @_osa1 to introduce this feature to GHC. It's a pity community didn't help with it.
github.com/ghc-proposals/ghc…
I am team #PatternGuards for this reason, minimal indentation, branching, let declaration, pattern matching that can introduce local constraints
foo :: forall a. Typeable a => a
foo
| App f _ <- TypeRep @a
, Just HRefl <- eqTypeRep (TypeRep @[]) f
= []
when I'm writing
map (\a -> ..)
& need guards (also useful for bringing constraints into local scope!) I don't think to write
map (\case a | .. -> ..)
because I'm not case-ing on 'a', I just hijack its #PatternGuards. Would I actually prefer
map (\a | .. -> ..)
who knows
It's the #PatternGuards syntax
foo a
| a < 0
= ..
| otherwise
= ..
which allows let bindings ('| let' is incidentally a drop in replacement for '| otherwise'), all of these let binding are accepts: